Add initial API support for listing configured servers

This commit is contained in:
Dane Everitt
2019-04-05 22:20:26 -07:00
parent ec2407481b
commit cedbee5080
5 changed files with 67 additions and 20 deletions

33
http.go Normal file
View File

@@ -0,0 +1,33 @@
package main
import (
"encoding/json"
"fmt"
"github.com/julienschmidt/httprouter"
"github.com/pterodactyl/wings/server"
"net/http"
)
type Router struct {
Servers []*server.Server
}
func (r *Router) routeIndex(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func (r *Router) routeAllServers(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
enc := json.NewEncoder(w)
enc.Encode(r.Servers)
}
func (r *Router) ConfigureRouter() *httprouter.Router {
router := httprouter.New()
router.GET("/", r.routeIndex)
router.GET("/api/servers", r.routeAllServers)
// router.GET("/api/servers/:server", r.routeServer)
return router
}