-
Notifications
You must be signed in to change notification settings - Fork 4
/
servers.go
70 lines (61 loc) · 1.65 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
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
package client
import (
"context"
"encoding/json"
"fmt"
consts "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/common"
models "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
)
type ServersAPIService struct {
Client APIClientHandler
Cfg Configuration
}
/*
ServersApiService
Get All Servers
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc.
Passed from http.Request or context.Background().
* @param name/phrase optional
@return models.Servers
*/
func (a *ServersAPIService) GetAllServers(
ctx context.Context,
queryParams map[string]string,
) (models.ServersResponse, error) {
serversResponse := models.ServersResponse{}
serverAPI := &api{
method: "GET",
path: consts.ServerPath,
client: a.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &serversResponse)
},
}
err := serverAPI.do(ctx, nil, queryParams)
return serversResponse, err
}
func (a *ServersAPIService) GetSpecificServer(
ctx context.Context,
serverID int) (models.GetSpecificServerResponse, error) {
serversResponse := models.GetSpecificServerResponse{}
serverAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%d",
consts.ServerPath, serverID),
client: a.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &serversResponse)
},
validations: []validationFunc{
func() error {
if serverID < 1 {
return fmt.Errorf("%s", "server id should be greater than or equal to 1")
}
return nil
},
},
}
err := serverAPI.do(ctx, nil, nil)
return serversResponse, err
}