refactor(*): Break apart packages

This commit is contained in:
Brian Waldon
2014-03-18 09:00:41 -07:00
parent 5185fe48da
commit d2dabee0c6
21 changed files with 330 additions and 262 deletions

6
datasource/datasource.go Normal file
View File

@@ -0,0 +1,6 @@
package datasource
type Datasource interface {
Fetch() ([]byte, error)
Type() string
}

21
datasource/file.go Normal file
View File

@@ -0,0 +1,21 @@
package datasource
import (
"io/ioutil"
)
type localFile struct {
path string
}
func NewLocalFile(path string) *localFile {
return &localFile{path}
}
func (self *localFile) Fetch() ([]byte, error) {
return ioutil.ReadFile(self.path)
}
func (self *localFile) Type() string {
return "local-file"
}

View File

@@ -0,0 +1,38 @@
package datasource
import (
"io/ioutil"
"net/http"
)
type metadataService struct {
url string
client http.Client
}
func NewMetadataService(url string) *metadataService {
return &metadataService{url, http.Client{}}
}
func (ms *metadataService) Fetch() ([]byte, error) {
resp, err := ms.client.Get(ms.url)
if err != nil {
return []byte{}, err
}
defer resp.Body.Close()
if resp.StatusCode / 100 != 2 {
return []byte{}, nil
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return respBytes, nil
}
func (ms *metadataService) Type() string {
return "metadata-service"
}