-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
43 lines (35 loc) · 797 Bytes
/
config.go
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
37
38
39
40
41
42
43
package main
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
type Config struct {
ServerHost string `yaml:"server_host"`
ServerAddr string `yaml:"server_addr"`
DiscoveryXmlUrl string `yaml:"discovery_xml_url"`
StorageRoot string `yaml:"storage_root"`
TokenLifetime int64 `yaml:"token_lifetime"`
}
/**
* Create new config object
* @return *Config
*/
func CreateNewConfig() *Config {
return &Config{}
}
/**
* Load data from file
* @param string
* @return *Config
*/
func LoadConfigYAML(configFilePath string) (*Config, error) {
config := CreateNewConfig()
configFileData, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, err
}
if err = yaml.Unmarshal([]byte(configFileData), config); err != nil {
return nil, err
}
return config, nil
}