-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
36 lines (29 loc) · 725 Bytes
/
config.go
File metadata and controls
36 lines (29 loc) · 725 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
package main
import (
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// Config represents the configuration structure
type Config struct {
ListenAddr string `yaml:"listenAddr"`
RemoteAddr string `yaml:"remoteAddr"`
CertDir string `yaml:"certDir"`
}
// ReadConfig reads the configuration from the specified path
func ReadConfig() (*Config, error) {
configPath := "/etc/influx/config.yml"
if _, err := os.Stat(configPath); os.IsNotExist(err) {
configPath = "./config.yml" // fallback to local config file on Windows
}
data, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return &config, nil
}