-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
47 lines (37 loc) · 834 Bytes
/
conf.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
47
package main
import (
"encoding/json"
"os"
)
type Config struct {
Port int `json:"port"`
Bucket Bucket `json:"bucket"`
Postgresql Postgresql `json:"postgresql"`
}
type Bucket struct {
Endpoint string `json:"endpoint"`
Region string `json:"region"`
Name string `json:"name"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
}
type Postgresql struct {
Database string `json:"database"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
}
func GetConfig(configFile string) (*Config, error) {
var c Config
file, err := os.Open(configFile)
if err != nil {
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&c)
if err != nil {
return nil, err
}
return &c, nil
}