diff --git a/api/api.go b/api/api.go index 1158db0..366b6e9 100644 --- a/api/api.go +++ b/api/api.go @@ -2,16 +2,17 @@ package api import ( "fmt" - "html" "net/http" + "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" - "github.com/schrej/wings/config" + "github.com/Pterodactyl/wings/config" ) // API is a grouping struct for the api type API struct { + router *gin.Engine } // NewAPI creates a new Api object @@ -21,12 +22,22 @@ func NewAPI() API { // Listen starts the api http server func (api *API) Listen() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) - }) + if !config.Get().Debug { + gin.SetMode(gin.ReleaseMode) + } + + api.router = gin.Default() + + api.router.GET("/", getRoot) listenString := fmt.Sprintf("%s:%d", config.Get().Web.ListenHost, config.Get().Web.ListenPort) + api.router.Run(listenString) + log.Info("Now listening on %s", listenString) log.Fatal(http.ListenAndServe(listenString, nil)) } + +func getRoot(c *gin.Context) { + c.String(http.StatusOK, "hello!") +}