Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
Add post endpoint to generate uuid for server
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Mar 6, 2018
1 parent 5eb42de commit 781c036
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions routing/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
ppErrors "github.com/pufferpanel/pufferd/errors"
"github.com/pufferpanel/pufferd/httphandlers"
"github.com/pufferpanel/pufferd/programs"

"github.com/satori/go.uuid"
)

var wsupgrader = websocket.Upgrader{
Expand Down Expand Up @@ -86,6 +88,7 @@ func RegisterRoutes(e *gin.Engine) {
l.GET("/:id/stats", httphandlers.OAuth2Handler("server.stats", true), GetStats)
l.GET("/:id/status", httphandlers.OAuth2Handler("server.stats", true), GetStatus)
}
l.POST("/server", httphandlers.OAuth2Handler("server.create", false), CreateServer)
e.GET("/network", httphandlers.OAuth2Handler("server.network", false), NetworkServer)
}

Expand Down Expand Up @@ -134,6 +137,14 @@ func KillServer(c *gin.Context) {

func CreateServer(c *gin.Context) {
serverId := c.Param("id")
if serverId == "" {
uuid, err := uuid.NewV4()
if err != nil {
http.Respond(c).Status(500).Message("error generating uuid").Data(err).Code(http.UNKNOWN).Send()
return
}
serverId = uuid.String()
}
prg, _ := programs.Get(serverId)

if prg != nil {
Expand All @@ -155,6 +166,8 @@ func CreateServer(c *gin.Context) {
if !programs.Create(serverId, typeServer, data) {
errorConnection(c, nil)
} else {
data := make(map[string]interface{})
data["id"] = serverId
http.Respond(c).Send()
}
}
Expand Down

0 comments on commit 781c036

Please sign in to comment.