-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
53 lines (45 loc) · 849 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
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"os"
"github.com/naoina/toml"
)
//TomlConfig implement toml config file in Go.
type TomlConfig struct {
Title string
Log struct {
Type string
NetworkType string
Host string
Severity string
Facility string
Port string
FilePath string
FileName string
DebugMode bool
}
}
var (
//Config struct
Config *TomlConfig
)
func getConfig(configFileName string) (*TomlConfig, error) {
var config TomlConfig
f, err := os.Open(configFileName)
if err != nil {
return nil, err
}
defer f.Close()
buf, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
if err := toml.Unmarshal(buf, &config); err != nil {
return nil, err
}
return &config, nil
}
var configPath string
func configure() (*TomlConfig, error) {
return getConfig(configPath)
}