/
api_service.go
69 lines (61 loc) · 1.69 KB
/
api_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
69
package globalsearchv2
import (
gohttp "net/http"
bluemix "github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/authentication"
"github.com/IBM-Cloud/bluemix-go/client"
"github.com/IBM-Cloud/bluemix-go/http"
"github.com/IBM-Cloud/bluemix-go/rest"
"github.com/IBM-Cloud/bluemix-go/session"
)
//ErrCodeAPICreation ...
const ErrCodeAPICreation = "APICreationError"
//ICDServiceAPI is the Cloud Internet Services API ...
type GlobalSearchServiceAPI interface {
Searches() Searches
}
//ICDService holds the client
type globalSearchService struct {
*client.Client
}
//New ...
func New(sess *session.Session) (GlobalSearchServiceAPI, error) {
config := sess.Config.Copy()
err := config.ValidateConfigForService(bluemix.GlobalSearchService)
if err != nil {
return nil, err
}
if config.HTTPClient == nil {
config.HTTPClient = http.NewHTTPClient(config)
}
tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
DefaultHeader: gohttp.Header{
"X-Original-User-Agent": []string{config.UserAgent},
"User-Agent": []string{http.UserAgent()},
},
HTTPClient: config.HTTPClient,
})
if err != nil {
return nil, err
}
if config.IAMAccessToken == "" {
err := authentication.PopulateTokens(tokenRefreher, config)
if err != nil {
return nil, err
}
}
if config.Endpoint == nil {
ep, err := config.EndpointLocator.GlobalSearchEndpoint()
if err != nil {
return nil, err
}
config.Endpoint = &ep
}
return &globalSearchService{
Client: client.New(config, bluemix.GlobalSearchService, tokenRefreher),
}, nil
}
//Search implements the global search API
func (c *globalSearchService) Searches() Searches {
return newSearchAPI(c.Client)
}