func FileDeleteHandler(storage storage.Storage, writer http.ResponseWriter, request *http.Request) { err := storage.Delete(mux.Vars(request)["id"]) if err != nil { log.Println("File delete error: ", err) writeResponseToIdRequestError(writer, err) } }
func FilePostHandler(storage storage.Storage, writer http.ResponseWriter, request *http.Request) { id, err := storage.Post(request.Body) if err != nil { log.Println("File post error: ", err) writer.WriteHeader(http.StatusInternalServerError) } else { writer.Write([]byte(id)) } }
func FileGetListHandler(storage storage.Storage, writer http.ResponseWriter, request *http.Request) { ids, err := storage.GetList() if err != nil { log.Println("File get list error: ", err) writer.WriteHeader(http.StatusInternalServerError) } else { json, err := json.Marshal(ids) if err != nil { log.Println("JSON marshalling error: ", err) writer.WriteHeader(http.StatusInternalServerError) } else { writer.Header().Set("Content-Type", "application/json") writer.Write(json) } } }