2017-06-18 22:01:44 +00:00
|
|
|
package api
|
2017-06-26 09:07:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2017-07-06 18:55:26 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2017-06-26 18:44:37 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2017-08-31 18:13:01 +00:00
|
|
|
"github.com/spf13/viper"
|
2017-06-26 09:07:53 +00:00
|
|
|
|
2017-07-06 18:55:26 +00:00
|
|
|
"github.com/Pterodactyl/wings/config"
|
2017-06-26 09:07:53 +00:00
|
|
|
)
|
|
|
|
|
2017-09-30 23:35:44 +00:00
|
|
|
type InternalAPI struct {
|
2017-07-06 18:55:26 +00:00
|
|
|
router *gin.Engine
|
2017-06-26 09:07:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 23:35:44 +00:00
|
|
|
func NewAPI() InternalAPI {
|
|
|
|
return InternalAPI{}
|
2017-06-26 09:07:53 +00:00
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
2017-08-31 18:13:01 +00:00
|
|
|
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
|
|
|
}
|