-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
42 lines (33 loc) · 945 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 main
import (
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Database Database `yaml:"database"`
}
type Database struct {
Influxdb Influxdb `yaml:"influxdb"`
}
type Influxdb struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Database string `yaml:"database"`
RetentionPolicy string `yaml:"retention_policy"`
}
func GetConfig(configfile string) (*Config, error) {
// buka berkas konfigurasi
file, err := os.Open(configfile)
if err != nil {
return nil, err
}
defer file.Close()
config := &Config{}
d := yaml.NewDecoder(file)
if err := d.Decode(&config); err != nil {
return nil, err
}
return config, nil
}