-
Notifications
You must be signed in to change notification settings - Fork 6
/
location.go
103 lines (90 loc) · 2.85 KB
/
location.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
package resources
import (
"context"
"github.com/ionos-cloud/ionosctl/v6/internal/client"
"github.com/fatih/structs"
ionoscloud "github.com/ionos-cloud/sdk-go/v6"
)
type Location struct {
ionoscloud.Location
}
type CpuArchitectureProperties struct {
ionoscloud.CpuArchitectureProperties
}
type Locations struct {
ionoscloud.Locations
}
// LocationsService is a wrapper around ionoscloud.Location
type LocationsService interface {
List(params ListQueryParams) (Locations, *Response, error)
GetByRegionAndLocationId(regionId, locationId string, params QueryParams) (*Location, *Response, error)
GetByRegionId(regionId string, params QueryParams) (Locations, *Response, error)
}
type locationsService struct {
client *ionoscloud.APIClient
context context.Context
}
var _ LocationsService = &locationsService{}
func NewLocationService(client *client.Client, ctx context.Context) LocationsService {
return &locationsService{
client: client.CloudClient,
context: ctx,
}
}
func (s *locationsService) List(params ListQueryParams) (Locations, *Response, error) {
req := s.client.LocationsApi.LocationsGet(s.context)
if !structs.IsZero(params) {
if params.Filters != nil {
for k, v := range *params.Filters {
for _, val := range v {
req = req.Filter(k, val)
}
}
}
if params.OrderBy != nil {
req = req.OrderBy(*params.OrderBy)
}
if params.MaxResults != nil {
req = req.MaxResults(*params.MaxResults)
}
if !structs.IsZero(params.QueryParams) {
if params.QueryParams.Depth != nil {
req = req.Depth(*params.QueryParams.Depth)
}
if params.QueryParams.Pretty != nil {
// Currently not implemented
req = req.Pretty(*params.QueryParams.Pretty)
}
}
}
locations, resp, err := s.client.LocationsApi.LocationsGetExecute(req)
return Locations{locations}, &Response{*resp}, err
}
func (s *locationsService) GetByRegionAndLocationId(regionId, locationId string, params QueryParams) (*Location, *Response, error) {
req := s.client.LocationsApi.LocationsFindByRegionIdAndId(s.context, regionId, locationId)
if !structs.IsZero(params) {
if params.Depth != nil {
req = req.Depth(*params.Depth)
}
if params.Pretty != nil {
// Currently not implemented
req = req.Pretty(*params.Pretty)
}
}
loc, resp, err := s.client.LocationsApi.LocationsFindByRegionIdAndIdExecute(req)
return &Location{loc}, &Response{*resp}, err
}
func (s *locationsService) GetByRegionId(regionId string, params QueryParams) (Locations, *Response, error) {
req := s.client.LocationsApi.LocationsFindByRegionId(s.context, regionId)
if !structs.IsZero(params) {
if params.Depth != nil {
req = req.Depth(*params.Depth)
}
if params.Pretty != nil {
// Currently not implemented
req = req.Pretty(*params.Pretty)
}
}
locs, resp, err := s.client.LocationsApi.LocationsFindByRegionIdExecute(req)
return Locations{locs}, &Response{*resp}, err
}