cloudinit/datasource/metadata_service.go

39 lines
628 B
Go
Raw Normal View History

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()
if resp.StatusCode / 100 != 2 {
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"
}