package handlers import ( "fmt" "github.com/gorilla/mux" "mazeratsgen/internal/dice" "mazeratsgen/internal/tables" "net/http" "strconv" "time" ) // @Summary Generate a city // @Tags city // @Produce application/json, text/plain // @Method GET // @Router /api/generate/city [get] // @Success 200 {object} tables.City func GenCity(w http.ResponseWriter, r *http.Request) { t := tables.CityTable{Roller: dice.NewRoller((time.Now().UnixNano()))} WriteResponse(w, r, t.Generate(), t.Template()) } // @Summary Generate a specific city using a seed // @Tags city // @Produce application/json, text/plain // @Method GET // @Router /api/city/{seed} [get] // @Param seed path int64 true "Int64" // @Success 200 {object} tables.City func City(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) seed, err := strconv.ParseInt(vars["seed"], 10, 64) if err != nil { w.Write([]byte(fmt.Sprintf("Unable to parse '%v' as Int64", vars["seed"]))) return } t := tables.CityTable{Roller: dice.NewRoller(seed)} WriteResponse(w, r, t.Generate(), t.Template()) }