blob: 3f1116cd8ddfeda3d3f44c2db90658ab0eb3ce13 (
plain)
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
|
package main
import (
"encoding/json"
"fmt"
"os"
)
type Config struct {
// database
DBDriver string `json:"db_driver"`
DBDBName string `json:"db_dbname"`
DBHost string `json:"db_host"`
DBPort string `json:"db_port"`
DBUser string `json:"db_user"`
DBPassword string `json:"db_password"`
DBOptions string `json:"db_options"`
// http client
UserAgent string `json:"user_agent"`
Delay int `json:"delay"`
// auth
RefreshToken string `json:"refresh_token"`
// misc
Debug bool `json:"debug"`
}
var _conf = Config{}
// LoadConfig reads a JSON config file and returns a populated Config.
func LoadConfig(path string) (*Config, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("config: open %s: %w", path, err)
}
defer f.Close()
c := &Config{}
if err := json.NewDecoder(f).Decode(c); err != nil {
return nil, fmt.Errorf("config: decode %s: %w", path, err)
}
return c, nil
}
|