-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcompute_provider_service.go
46 lines (38 loc) · 1.05 KB
/
compute_provider_service.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
package ai
import (
"bytes"
"fmt"
"io"
"path"
"github.com/go-playground/validator/v10"
)
type ComputeProviderService struct {
client *Client
validate *validator.Validate
}
type UpdateRequest struct {
AccessKey string `json:"accessKey" Validate:"required"`
SecretKey string `json:"secretKey" Validate:"required"`
}
func (s *ComputeProviderService) path(components ...string) string {
return path.Join(components...)
}
func (s *ComputeProviderService) UpdateProvider(request UpdateRequest) (bool, *Response, error) {
if err := s.validate.Struct(request); err != nil {
return false, nil, err
}
req, err := s.client.NewAIRequest("POST", s.path("ComputeProvider"), request, nil)
if err != nil {
return false, nil, err
}
req.Header.Set("Api-Version", APIVersion)
var operationOutcome bytes.Buffer
resp, err := s.client.Do(req, &operationOutcome)
if (err != nil && err != io.EOF) || resp == nil {
if resp == nil && err != nil {
err = fmt.Errorf("UpdateProvider: %w", ErrEmptyResult)
}
return false, resp, err
}
return true, resp, nil
}