package handlers import ( "fmt" "github.com/gorilla/mux" "mazeratsgen/internal/dice" "mazeratsgen/internal/tables" "net/http" "strconv" "time" ) // @Summary Generate a dungeon // @Tags dungeon // @Produce application/json, text/plain // @Method GET // @Router /api/generate/dungeon [get] // @Success 200 {object} tables.Maze func GenDungeon(w http.ResponseWriter, r *http.Request) { t := tables.MazeTable{Roller: dice.NewRoller((time.Now().UnixNano()))} WriteResponse(w, r, t.Generate(), t.Template()) } // @Summary Generate a specific dungeon using a seed // @Tags dungeon // @Produce application/json, text/plain // @Method GET // @Router /api/dungeon/{seed} [get] // @Param seed path int64 true "Int64" // @Success 200 {object} tables.Maze func Dungeon(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.MazeTable{Roller: dice.NewRoller(seed)} WriteResponse(w, r, t.Generate(), t.Template()) }