forked from go-acd/acd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints.go
43 lines (36 loc) · 1.02 KB
/
endpoints.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
package acd
import (
"encoding/json"
"net/http"
"gopkg.in/acd.v0/internal/constants"
"gopkg.in/acd.v0/internal/log"
)
// GetMetadataURL returns the metadata url.
func (c *Client) GetMetadataURL(path string) string {
return c.metadataURL + path
}
// GetContentURL returns the content url.
func (c *Client) GetContentURL(path string) string {
return c.contentURL + path
}
func setEndpoints(c *Client) error {
req, err := http.NewRequest("GET", endpointURL, nil)
if err != nil {
log.Errorf("%s: %s", constants.ErrCreatingHTTPRequest, err)
return constants.ErrCreatingHTTPRequest
}
var er endpointResponse
res, err := c.Do(req)
if err != nil {
log.Errorf("%s: %s", constants.ErrDoingHTTPRequest, err)
return constants.ErrDoingHTTPRequest
}
defer res.Body.Close()
if err := json.NewDecoder(res.Body).Decode(&er); err != nil {
log.Errorf("%s: %s", constants.ErrJSONDecodingResponseBody, err)
return constants.ErrJSONDecodingResponseBody
}
c.contentURL = er.ContentURL
c.metadataURL = er.MetadataURL
return nil
}