-
Notifications
You must be signed in to change notification settings - Fork 14
/
service.go
68 lines (54 loc) · 1.96 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Code generated by sysl DO NOT EDIT.
package deps
import (
"context"
"fmt"
"net/http"
"net/url"
"github.com/anz-bank/sysl-go/common"
"github.com/anz-bank/sysl-go/restlib"
"github.com/anz-bank/sysl-go/validator"
)
// Service interface for Deps
type Service interface {
GetApiDocsList(ctx context.Context, req *GetApiDocsListRequest) (*ApiDoc, error)
}
// Client for Deps API
type Client struct {
client *http.Client
url string
}
// NewClient for Deps
func NewClient(client *http.Client, serviceURL string) *Client {
return &Client{client, serviceURL}
}
// GetApiDocsList ...
func (s *Client) GetApiDocsList(ctx context.Context, req *GetApiDocsListRequest) (*ApiDoc, error) {
required := []string{}
var okResponse ApiDoc
var errorResponse Status
u, err := url.Parse(fmt.Sprintf("%s/api-docs", s.url))
if err != nil {
return nil, common.CreateError(ctx, common.InternalError, "failed to parse url", err)
}
result, err := restlib.DoHTTPRequest(ctx, s.client, "GET", u.String(), nil, required, &okResponse, &errorResponse)
if err != nil {
response, ok := err.(*restlib.HTTPResult)
if !ok {
return nil, common.CreateError(ctx, common.DownstreamUnavailableError, "call failed: Deps <- GET "+u.String(), err)
}
return nil, common.CreateDownstreamError(ctx, common.DownstreamResponseError, response.HTTPResponse, response.Body, &errorResponse)
}
if result.HTTPResponse.StatusCode == http.StatusUnauthorized {
return nil, common.CreateDownstreamError(ctx, common.DownstreamUnauthorizedError, result.HTTPResponse, result.Body, nil)
}
OkApiDocResponse, ok := result.Response.(*ApiDoc)
if ok {
valErr := validator.Validate(OkApiDocResponse)
if valErr != nil {
return nil, common.CreateDownstreamError(ctx, common.DownstreamUnexpectedResponseError, result.HTTPResponse, result.Body, valErr)
}
return OkApiDocResponse, nil
}
return nil, common.CreateDownstreamError(ctx, common.DownstreamUnexpectedResponseError, result.HTTPResponse, result.Body, nil)
}