forked from Nomon/gonfig
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurl.go
More file actions
36 lines (32 loc) · 651 Bytes
/
url.go
File metadata and controls
36 lines (32 loc) · 651 Bytes
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
package unicon
import (
"io/ioutil"
"net/http"
)
// URLConfig is the url configurable
type URLConfig struct {
Configurable
url string
}
// NewURLConfig returns a new Configurable backed by JSON at url
func NewURLConfig(url string) ReadableConfig {
return &URLConfig{NewMemoryConfig(), url}
}
// Load attempts to read a json file at a remote address
func (uc *URLConfig) Load() error {
resp, err := http.Get(uc.url)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
out, err := unmarshalJSON(body)
if err != nil {
return err
}
uc.Reset(out)
return nil
}