/
config.go
42 lines (35 loc) · 809 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
package config
import (
"bufio"
"os"
"gopkg.in/yaml.v2"
)
// Config of auth service
type Config struct {
Server ServerConfig `yaml:"server"`
AccountService AccountServiceConfig `yaml:"AccountService"`
JWT JWTConfig `yaml:"jwt"`
}
type ServerConfig struct {
Port int `yaml:"port"`
}
type JWTConfig struct {
Algorithm string `yaml:"algorithm"`
PrivateKey string `yaml:"privateKey"`
PublicKey string `yaml:"publicKey"`
}
type AccountServiceConfig struct {
URL string `yaml:"url"`
}
// ReadConfig read and decode config file
func ReadConfig(file string) (Config, error) {
config := Config{}
f, err := os.Open(file)
if err != nil {
return config, err
}
r := bufio.NewReader(f)
d := yaml.NewDecoder(r)
err = d.Decode(&config)
return config, err
}