From 8a298f09a2440375d49b9446f49d8a81292b9df8 Mon Sep 17 00:00:00 2001 From: Hroman9n Date: Fri, 15 Dec 2023 21:26:20 +0300 Subject: [PATCH] add album API function handler --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.go b/main.go index 65b7130..bb9b245 100644 --- a/main.go +++ b/main.go @@ -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)