Fix details fetching for a single server instance

This commit is contained in:
Dane Everitt 2021-04-03 13:15:11 -07:00
parent 4c3b497652
commit d4b63bef39
2 changed files with 12 additions and 11 deletions

View File

@ -24,10 +24,9 @@ type serverProcData struct {
// Returns a single server from the collection of servers. // Returns a single server from the collection of servers.
func getServer(c *gin.Context) { func getServer(c *gin.Context) {
s := ExtractServer(c) s := ExtractServer(c)
c.JSON(http.StatusOK, ServerJsonResponse{
c.JSON(http.StatusOK, serverProcData{ Configuration: s.Config(),
ResourceUsage: s.Proc(), Resources: s.Proc(),
Suspended: s.IsSuspended(),
}) })
} }

View File

@ -14,6 +14,13 @@ import (
"github.com/pterodactyl/wings/system" "github.com/pterodactyl/wings/system"
) )
// ServerJsonResponse is a type returned when requesting details about a single
// server instance on Wings.
type ServerJsonResponse struct {
*server.Configuration
Resources server.ResourceUsage `json:"resources"`
}
// Returns information about the system that wings is running on. // Returns information about the system that wings is running on.
func getSystemInformation(c *gin.Context) { func getSystemInformation(c *gin.Context) {
i, err := system.GetSystemInformation() i, err := system.GetSystemInformation()
@ -29,15 +36,10 @@ func getSystemInformation(c *gin.Context) {
// Returns all of the servers that are registered and configured correctly on // Returns all of the servers that are registered and configured correctly on
// this wings instance. // this wings instance.
func getAllServers(c *gin.Context) { func getAllServers(c *gin.Context) {
type serverItem struct {
*server.Configuration
Resources server.ResourceUsage `json:"resources"`
}
servers := middleware.ExtractManager(c).All() servers := middleware.ExtractManager(c).All()
out := make([]serverItem, len(servers), len(servers)) out := make([]ServerJsonResponse, len(servers), len(servers))
for i, v := range servers { for i, v := range servers {
out[i] = serverItem{ out[i] = ServerJsonResponse{
Configuration: v.Config(), Configuration: v.Config(),
Resources: v.Proc(), Resources: v.Proc(),
} }