package main import ( "encoding/json" "fmt" "log" "net/http" "time" "github.com/gorilla/mux" "github.com/swaggo/http-swagger" _ "games.dcu.ie/hvz/v2/docs" ) // @title DCU Games Society Humans Vs Zombies // @version 1.0 // @description This is the Swagger documentation for DCU Games Society's 2022 Humans Vs Zombies event. // @host // @BasePath / func handleRequests() { myRouter := mux.NewRouter().StrictSlash(true) myRouter.HandleFunc("/", homePage) myRouter.PathPrefix("/docs/").Handler(httpSwagger.WrapHandler) log.Fatal(http.ListenAndServe(":8000", myRouter)) } // @Summary Home // @Description Home page // @Produce json // @Success 200 // @Router / [get] func homePage(w http.ResponseWriter, r *http.Request) { player := Player{ id: 0, name: "Malachy Byrne", state: 4, pin: "1234", infection_time: time.Now(), kills: 0, last_kill: time.Now(), } fmt.Println(player) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(player) } func main() { handleRequests() }