parent
76868519de
commit
edbae31636
12 changed files with 578 additions and 44 deletions
@ -0,0 +1,67 @@ |
|||||||
|
package handlers |
||||||
|
|
||||||
|
import ( |
||||||
|
"mazeratsgen/internal/dice" |
||||||
|
"mazeratsgen/internal/tables" |
||||||
|
"net/http" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
// @Summary Generate a spell
|
||||||
|
// @Tags magic
|
||||||
|
// @Produce application/json, text/plain
|
||||||
|
// @Method GET
|
||||||
|
// @Router /api/generate/spell [get]
|
||||||
|
// @Success 200
|
||||||
|
func GenSpell(w http.ResponseWriter, r *http.Request) { |
||||||
|
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
||||||
|
WriteResponse(w, r, t.Generate(), t.Template()) |
||||||
|
} |
||||||
|
|
||||||
|
// @Summary Generate a mutation
|
||||||
|
// @Tags magic
|
||||||
|
// @Produce application/json, text/plain
|
||||||
|
// @Method GET
|
||||||
|
// @Router /api/generate/mutation [get]
|
||||||
|
// @Success 200
|
||||||
|
func GenMutation(w http.ResponseWriter, r *http.Request) { |
||||||
|
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
||||||
|
mutation := t.Mutation(t.Roller.TableRoll()) |
||||||
|
WriteResponse(w, r, mutation, "{{.}}") |
||||||
|
} |
||||||
|
|
||||||
|
// @Summary Generate a insanity
|
||||||
|
// @Tags magic
|
||||||
|
// @Produce application/json, text/plain
|
||||||
|
// @Method GET
|
||||||
|
// @Router /api/generate/insanity [get]
|
||||||
|
// @Success 200
|
||||||
|
func GenInsanity(w http.ResponseWriter, r *http.Request) { |
||||||
|
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
||||||
|
i := t.Insanity(t.Roller.TableRoll()) |
||||||
|
WriteResponse(w, r, i, "{{.}}") |
||||||
|
} |
||||||
|
|
||||||
|
// @Summary Generate a catastrophe
|
||||||
|
// @Tags magic
|
||||||
|
// @Produce application/json, text/plain
|
||||||
|
// @Method GET
|
||||||
|
// @Router /api/generate/catastrophe [get]
|
||||||
|
// @Success 200
|
||||||
|
func GenCatastrophe(w http.ResponseWriter, r *http.Request) { |
||||||
|
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
||||||
|
c := t.Catastrophe(t.Roller.TableRoll()) |
||||||
|
WriteResponse(w, r, c, "{{.}}") |
||||||
|
} |
||||||
|
|
||||||
|
// @Summary Generate a catastrophe
|
||||||
|
// @Tags magic
|
||||||
|
// @Produce application/json, text/plain
|
||||||
|
// @Method GET
|
||||||
|
// @Router /api/generate/catastrophe [get]
|
||||||
|
// @Success 200
|
||||||
|
func GenCatastophe(w http.ResponseWriter, r *http.Request) { |
||||||
|
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
||||||
|
c := t.Catastrophe(t.Roller.TableRoll()) |
||||||
|
WriteResponse(w, r, c, "{{.}}") |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
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()) |
||||||
|
} |
@ -1,19 +0,0 @@ |
|||||||
package handlers |
|
||||||
|
|
||||||
import ( |
|
||||||
"mazeratsgen/internal/dice" |
|
||||||
"mazeratsgen/internal/tables" |
|
||||||
"net/http" |
|
||||||
"time" |
|
||||||
) |
|
||||||
|
|
||||||
// @Summary Generate a spell
|
|
||||||
// @Tags magic
|
|
||||||
// @Produce application/json, text/plain
|
|
||||||
// @Method GET
|
|
||||||
// @Router /api/generate/spell [get]
|
|
||||||
// @Success 200
|
|
||||||
func GenSpell(w http.ResponseWriter, r *http.Request) { |
|
||||||
t := tables.MagicTable{Roller: dice.NewRoller(time.Now().UnixNano())} |
|
||||||
WriteResponse(w, r, t.Generate(), t.Template()) |
|
||||||
} |
|
Loading…
Reference in new issue