From 9c364970f0082eeac05826018ee7881fce8c050c Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 6 Jul 2017 20:55:26 +0200 Subject: [PATCH] basic api server initialization --- api/api.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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!") +}