/
servers.go
132 lines (103 loc) · 4.02 KB
/
servers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package api
import (
"context"
"fmt"
"net/http"
"strings"
)
type ServersApiService service
/*
ServersApiService Create new Server.
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param region Region code
* @param body interface{}
@return interface{}
*/
func (a *ServersApiService) Create(ctx context.Context, region string, body interface{}) (interface{}, *http.Response, error) {
httpMethod := strings.ToUpper("Post")
// create path and map variables
path := a.client.cfg.BasePath + "/regions/{region}/servers"
path = strings.Replace(path, "{"+"region"+"}", fmt.Sprintf("%v", region), -1)
postBody := &body
r, err := a.client.prepareRequest(ctx, path, httpMethod, postBody)
if err != nil {
return nil, nil, err
}
return a.client.callAPI(r)
}
/*
ServersApiService Shows details of a Server.
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param region Region code
* @param id The ID of the server
@return interface{}
*/
func (a *ServersApiService) Get(ctx context.Context, region string, id string) (interface{}, *http.Response, error) {
httpMethod := strings.ToUpper("Get")
path := a.client.cfg.BasePath + "/regions/{region}/servers/{id}"
path = strings.Replace(path, "{"+"region"+"}", fmt.Sprintf("%v", region), -1)
path = strings.Replace(path, "{"+"id"+"}", fmt.Sprintf("%v", id), -1)
r, err := a.client.prepareRequest(ctx, path, httpMethod, nil)
if err != nil {
return nil, nil, err
}
return a.client.callAPI(r)
}
/*
ServersApiService Return all Servers.
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param region Region code
@return interface{}
*/
func (a *ServersApiService) All(ctx context.Context, region string) (interface{}, *http.Response, error) {
httpMethod := strings.ToUpper("Get")
// create path and map variables
path := a.client.cfg.BasePath + "/regions/{region}/servers"
path = strings.Replace(path, "{"+"region"+"}", fmt.Sprintf("%v", region), -1)
r, err := a.client.prepareRequest(ctx, path, httpMethod, nil)
if err != nil {
return nil, nil, err
}
return a.client.callAPI(r)
}
/*
ServersApiService Delete a Server.
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param region Region code
* @param id The ID of the server
* @param forceDelete Force delete
@return interface{}
*/
func (a *ServersApiService) Delete(ctx context.Context, region string, id string, forceDelete bool) (interface{}, *http.Response, error) {
httpMethod := strings.ToUpper("Delete")
// create path and map variables
path := a.client.cfg.BasePath + "/regions/{region}/servers/{id}"
path = strings.Replace(path, "{"+"region"+"}", fmt.Sprintf("%v", region), -1)
path = strings.Replace(path, "{"+"id"+"}", fmt.Sprintf("%v", id), -1)
// TODO: pass forceDelete to query params
// if forceDelete {
// // queryParams.Add("forceDelete", strconv.FormatBool(forceDelete))
// }
r, err := a.client.prepareRequest(ctx, path, httpMethod, nil)
if err != nil {
return nil, nil, err
}
return a.client.callAPI(r)
}
/*
ServersApiService Return a region options.
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param region Region code
@return interface{}
*/
func (a *ServersApiService) GetOptions(ctx context.Context, region string) (interface{}, *http.Response, error) {
httpMethod := strings.ToUpper("Get")
// create path and map variables
path := a.client.cfg.BasePath + "/regions/{region}/servers/options"
path = strings.Replace(path, "{"+"region"+"}", fmt.Sprintf("%v", region), -1)
r, err := a.client.prepareRequest(ctx, path, httpMethod, nil)
if err != nil {
return nil, nil, err
}
return a.client.callAPI(r)
}