-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
46 lines (38 loc) · 873 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
44
45
46
package exploregithub
import (
"errors"
"gopkg.in/yaml.v2"
"io/ioutil"
)
type DatabaseConfig struct {
Host string
Port string
User string
Password string
Database string
PoolSize int `yaml:"pool_size"`
}
type OAuthConfig struct {
ClientId string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
}
type ServerConfig struct {
Bind string `yaml:"bind"`
}
type Config struct {
Database DatabaseConfig `yaml:"database"`
Server ServerConfig `yaml:"server"`
OAuth OAuthConfig `yaml:"oauth"`
}
func NewConfig(path string) (*Config, error) {
var config Config
contents, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.New("failed to read configuration file")
}
err = yaml.Unmarshal(contents, &config)
if err != nil {
return nil, errors.New("failed to unmarshal file")
}
return &config, nil
}