catbase/plugins/cowboy/web.go

27 lines
527 B
Go
Raw Normal View History

2022-07-21 15:25:10 +00:00
package cowboy
import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
)
func (p *Cowboy) registerWeb() {
r := chi.NewRouter()
r.HandleFunc("/img/{what}", p.handleImage)
p.b.RegisterWeb(r, "/cowboy")
}
func (p *Cowboy) handleImage(w http.ResponseWriter, r *http.Request) {
what := chi.URLParam(r, "what")
2022-07-22 22:27:20 +00:00
img, err := encode(cowboy(p.c, p.emojyPath, p.baseEmojyURL, what))
2022-07-21 15:25:10 +00:00
if err != nil {
w.WriteHeader(500)
fmt.Fprintf(w, "Error: %s", err)
return
}
w.Header().Add("Content-Type", "image/png")
w.Write(img)
}