github.com/devcamcar/cli@v0.0.0-20181107134215-706a05759d18/config/context_file.go (about) 1 package config 2 3 import ( 4 "io/ioutil" 5 6 "github.com/go-yaml/yaml" 7 ) 8 9 // ContextFile defines the internal structure of a default context 10 type ContextFile struct { 11 ContextProvider string `yaml:"provider" json:"provider"` 12 EnvFnAPIURL string `yaml:"api-url" json:"apiUrl"` 13 EnvFnRegistry string `yaml:"registry" json:"registry"` 14 } 15 16 // NewContextFile creates a new instance of the context YAML file 17 func NewContextFile(filePath string) (*ContextFile, error) { 18 c := &ContextFile{} 19 contents, err := ioutil.ReadFile(filePath) 20 if err != nil { 21 return c, err 22 } 23 if err = yaml.Unmarshal(contents, c); err != nil { 24 return c, err 25 } 26 return c, nil 27 }