package main import ( "net/http" database "nefrace.ru/doomer/db" "nefrace.ru/doomer/server" ) func InitServer(host string) server.Api { app := server.NewApi(host) app.Group("/api").Endpoint("gen", ImageHandler) return app } func ImageHandler(w http.ResponseWriter, r *http.Request) error { db := database.DB() doomer := NewDoomer(db) text := r.URL.Query().Get("text") img, err := doomer.GetImage(text, Black) if err != nil { return server.ApiError{ Err: "cannot generate image: " + err.Error(), Status: http.StatusInternalServerError, } } return server.WriteBlob(w, 200, "image/png", *img) }