Example #1
0
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)
	}
}
Example #2
0
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))
	}
}
Example #3
0
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)
		}
	}
}