Clean up route handling

This commit is contained in:
Dane Everitt
2017-09-30 18:35:44 -05:00
parent 256c566dfe
commit 1bfc016e1b
9 changed files with 163 additions and 173 deletions

View File

@@ -11,34 +11,26 @@ import (
"github.com/Pterodactyl/wings/config"
)
// API is a grouping struct for the api
type API struct {
type InternalAPI struct {
router *gin.Engine
}
// NewAPI creates a new Api object
func NewAPI() API {
return API{}
func NewAPI() InternalAPI {
return InternalAPI{}
}
// Listen starts the api http server
func (api *API) Listen() {
// 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) {
gin.SetMode(gin.ReleaseMode)
}
api.router = gin.Default()
api.RegisterRoutes()
api.registerRoutes()
listenString := fmt.Sprintf("%s:%d", viper.GetString(config.APIHost), viper.GetInt(config.APIPort))
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!")
api.router.Run(listener)
log.Info("Now listening on %s", listener)
log.Fatal(http.ListenAndServe(listener, nil))
}