Go binary/server for helping run/build sessions for the Maze Rats TTRPG
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
1.1 KiB

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