basic api server initialization
This commit is contained in:
parent
e356ee5fa8
commit
9c364970f0
21
api/api.go
21
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!")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user