package handlers import ( "github.com/gorilla/mux" "mazeratsgen/internal/dice" "net/http" "time" ) // @Summary Roll some dice // @Tags dice // @Produce application/json, text/plain // @Method GET // @Router /api/roll/{xdy} [get] // @Param xdy path string true "Roll in xdy format (e.g. 1d6)" // @Success 200 func Roll(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) roller := dice.NewRoller(time.Now().UnixNano()) response, err := roller.Roll(vars["xdy"]) if err != nil { w.WriteHeader(http.StatusInternalServerError) // TODO: Return json error w.Write([]byte(err.Error())) return } template := "{{ range . }}{{ . }}\n{{end}}" WriteResponse(w, r, response, template) }