2014-03-18 20:00:41 +04:00
|
|
|
package datasource
|
2014-03-05 04:36:05 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type metadataService struct {
|
2014-03-05 05:06:52 +04:00
|
|
|
url string
|
2014-03-05 04:36:05 +04:00
|
|
|
client http.Client
|
|
|
|
}
|
|
|
|
|
2014-03-05 05:06:52 +04:00
|
|
|
func NewMetadataService(url string) *metadataService {
|
|
|
|
return &metadataService{url, http.Client{}}
|
2014-03-05 04:36:05 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 20:00:41 +04:00
|
|
|
func (ms *metadataService) Fetch() ([]byte, error) {
|
2014-03-05 05:06:52 +04:00
|
|
|
resp, err := ms.client.Get(ms.url)
|
2014-03-05 04:36:05 +04:00
|
|
|
if err != nil {
|
|
|
|
return []byte{}, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2014-03-14 08:12:14 +04:00
|
|
|
|
2014-03-14 08:47:59 +04:00
|
|
|
if resp.StatusCode / 100 != 2 {
|
2014-03-14 08:12:14 +04:00
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:36:05 +04:00
|
|
|
respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return respBytes, nil
|
|
|
|
}
|
|
|
|
|
2014-03-18 20:00:41 +04:00
|
|
|
func (ms *metadataService) Type() string {
|
|
|
|
return "metadata-service"
|
|
|
|
}
|