wings/api/api.go

37 lines
719 B
Go
Raw Normal View History

package api
import (
"fmt"
"net/http"
2017-07-06 18:55:26 +00:00
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
2017-07-06 18:55:26 +00:00
"github.com/Pterodactyl/wings/config"
)
2017-09-30 23:35:44 +00:00
type InternalAPI struct {
2017-07-06 18:55:26 +00:00
router *gin.Engine
}
2017-09-30 23:35:44 +00:00
func NewAPI() InternalAPI {
return InternalAPI{}
}
2017-09-30 23:35:44 +00:00
// Configure the API and begin listening on the configured IP and Port.
func (api *InternalAPI) Listen() {
listener := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort))
if !viper.GetBool(config.Debug) {
2017-07-06 18:55:26 +00:00
gin.SetMode(gin.ReleaseMode)
}
api.router = gin.Default()
2017-09-30 23:35:44 +00:00
api.RegisterRoutes()
2017-07-06 18:55:26 +00:00
2017-09-30 23:35:44 +00:00
api.router.Run(listener)
log.Info("Now listening on %s", listener)
log.Fatal(http.ListenAndServe(listener, nil))
2017-07-06 18:55:26 +00:00
}