Skip to content

Commit 452482c

Browse files
committed
Rename now uses generic PatchServer
1 parent 3b62423 commit 452482c

File tree

2 files changed

+4
-36
lines changed

2 files changed

+4
-36
lines changed

api.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,6 @@ type ScalewayServerPatchDefinition struct {
399399
//Tags *[]string `json:"tags",omitempty`
400400
}
401401

402-
// ScalewayServerPatchNameDefinition represents a Scaleway C1 server with only its name as field
403-
type ScalewayServerPatchNameDefinition struct {
404-
// Name is the user-defined name of the server
405-
Name string `json:"name"`
406-
}
407-
408402
// ScalewayServerDefinition represents a Scaleway C1 server with image definition
409403
type ScalewayServerDefinition struct {
410404
// Name is the user-defined name of the server
@@ -701,32 +695,6 @@ func (s *ScalewayAPI) PostServer(definition ScalewayServerDefinition) (string, e
701695
return "", error
702696
}
703697

704-
// PatchServerName changes the name of the server
705-
func (s *ScalewayAPI) PatchServerName(serverID string, definition ScalewayServerPatchNameDefinition) error {
706-
resp, err := s.PatchResponse(fmt.Sprintf("servers/%s", serverID), definition)
707-
if err != nil {
708-
return err
709-
}
710-
711-
defer resp.Body.Close()
712-
decoder := json.NewDecoder(resp.Body)
713-
714-
// Succeed PATCH code
715-
if resp.StatusCode == 200 {
716-
return nil
717-
}
718-
719-
var error ScalewayAPIError
720-
err = decoder.Decode(&error)
721-
if err != nil {
722-
return err
723-
}
724-
725-
error.StatusCode = resp.StatusCode
726-
error.Debug()
727-
return error
728-
}
729-
730698
// PatchServer updates a server
731699
func (s *ScalewayAPI) PatchServer(serverID string, definition ScalewayServerPatchDefinition) error {
732700
resp, err := s.PatchResponse(fmt.Sprintf("servers/%s", serverID), definition)

rename.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func runRename(cmd *Command, args []string) {
2626

2727
serverID := cmd.API.GetServerID(args[0])
2828

29-
var server ScalewayServerPatchNameDefinition
30-
server.Name = args[1]
29+
var server ScalewayServerPatchDefinition
30+
server.Name = &args[1]
3131

32-
err := cmd.API.PatchServerName(serverID, server)
32+
err := cmd.API.PatchServer(serverID, server)
3333
if err != nil {
3434
log.Fatalf("Cannot rename server: %v", err)
3535
} else {
36-
cmd.API.Cache.InsertServer(serverID, server.Name)
36+
cmd.API.Cache.InsertServer(serverID, *server.Name)
3737
}
3838
}

0 commit comments

Comments
 (0)