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 13:44:42 +00:00
|
|
|
img, err := 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)
|
|
|
|
}
|