Merge pull request #34 from rahonavis/2078-bindjson
#2078 - fix BindJSON calls
This commit is contained in:
commit
00a026c2a5
|
@ -46,7 +46,10 @@ func postServerPower(c *gin.Context) {
|
|||
s := GetServer(c.Param("server"))
|
||||
|
||||
var data server.PowerAction
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !data.IsValid() {
|
||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||
|
@ -98,8 +101,13 @@ func postServerCommands(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
var data struct{ Commands []string `json:"commands"` }
|
||||
c.BindJSON(&data)
|
||||
var data struct {
|
||||
Commands []string `json:"commands"`
|
||||
}
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, command := range data.Commands {
|
||||
if err := s.Environment.SendCommand(command); err != nil {
|
||||
|
|
|
@ -15,7 +15,10 @@ func postServerBackup(c *gin.Context) {
|
|||
s := GetServer(c.Param("server"))
|
||||
|
||||
data := &backup.Request{}
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var adapter backup.BackupInterface
|
||||
var err error
|
||||
|
@ -41,7 +44,6 @@ func postServerBackup(c *gin.Context) {
|
|||
}
|
||||
}(adapter, s)
|
||||
|
||||
|
||||
c.Status(http.StatusAccepted)
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,10 @@ func putServerRenameFile(c *gin.Context) {
|
|||
RenameFrom string `json:"rename_from"`
|
||||
RenameTo string `json:"rename_to"`
|
||||
}
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if data.RenameFrom == "" || data.RenameTo == "" {
|
||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{
|
||||
|
@ -113,7 +116,10 @@ func postServerCopyFile(c *gin.Context) {
|
|||
var data struct {
|
||||
Location string `json:"location"`
|
||||
}
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.Filesystem.Copy(data.Location); err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
|
@ -130,7 +136,10 @@ func postServerDeleteFile(c *gin.Context) {
|
|||
var data struct {
|
||||
Location string `json:"location"`
|
||||
}
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.Filesystem.Delete(data.Location); err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
|
@ -167,7 +176,10 @@ func postServerCreateDirectory(c *gin.Context) {
|
|||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
c.BindJSON(&data)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.Filesystem.CreateDirectory(data.Name, data.Path); err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
|
|
|
@ -77,7 +77,10 @@ func postUpdateConfiguration(c *gin.Context) {
|
|||
// A copy of the configuration we're using to bind the data recevied into.
|
||||
cfg := *config.Get()
|
||||
|
||||
c.BindJSON(&cfg)
|
||||
// BindJSON sends 400 if the request fails, all we need to do is return
|
||||
if err := c.BindJSON(&cfg); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
config.Set(&cfg)
|
||||
if err := config.Get().WriteToDisk(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user