Skip to content

Commit

Permalink
add album API function handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Hroman9n committed Dec 15, 2023
1 parent d1ad3ef commit 8a298f0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func headers(w http.ResponseWriter, req *http.Request) {
}
}

func apiAlbum(w http.ResponseWriter, req *http.Request) {
rId := req.URL.Path
var retData = []album{}
if len(rId) > 0 {
for _, a := range albums {
if a.ID == rId {
retData = append(retData, a)
}
}
} else {
retData = albums
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(retData)
}

func main() {
http.HandleFunc("/", root)
http.HandleFunc("/hello", hello)
Expand Down

0 comments on commit 8a298f0

Please sign in to comment.