-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
38 lines (30 loc) · 735 Bytes
/
config.go
File metadata and controls
38 lines (30 loc) · 735 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
37
38
package wisdom_server
import (
"github.com/ilyakaznacheev/cleanenv"
"github.com/sirupsen/logrus"
"os"
"path"
)
const (
DefaultConfigPath = ".wisdom-server"
DefaultConfigFile = "config.yaml"
)
type Config struct {
Host string `yaml:"host"`
Port uint32 `yaml:"port"`
Timeout int64 `yaml:"timeout"`
SecretKey string `yaml:"secret_key"`
}
func ReadConfig() (*Config, error) {
config := &Config{}
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, err
}
configPath := path.Join(homeDir, DefaultConfigPath, DefaultConfigFile)
if err = cleanenv.ReadConfig(configPath, config); err != nil {
return nil, err
}
logrus.WithField("path", configPath).Info("Config loaded")
return config, nil
}