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