resell.go raw
1 package clients
2
3 import (
4 "fmt"
5
6 clientservices "github.com/selectel/go-selvpcclient/v4/selvpcclient/clients/services"
7 )
8
9 const (
10 ResellServiceType = "resell"
11 ResellAPIVersion = "v2"
12 )
13
14 // ResellClient resell client with X-Auth-Token authorization.
15 type ResellClient struct {
16 Requests *clientservices.RequestService
17 catalog *clientservices.CatalogService
18 region string
19 }
20
21 func NewResellClient(
22 requestService *clientservices.RequestService,
23 catalogService *clientservices.CatalogService,
24 region string,
25 ) *ResellClient {
26 return &ResellClient{
27 Requests: requestService,
28 catalog: catalogService,
29 region: region,
30 }
31 }
32
33 // GetEndpoint - returns service url.
34 func (c *ResellClient) GetEndpoint() (string, error) {
35 endpoint, err := c.catalog.GetEndpoint(ResellServiceType, c.region)
36 if err != nil {
37 return "", fmt.Errorf("failed to resolve endpoint for %s, err: %w", ResellServiceType, err)
38 }
39
40 url := fmt.Sprintf("%s/%s", endpoint.URL, ResellAPIVersion)
41
42 return url, nil
43 }
44