/
config.go
44 lines (38 loc) · 1.09 KB
/
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
/*
Package config provides utility functions to access the toml
objects defined in config.toml. Example of a config file is located at:
https://github.com/amadeovezz/gobro/tree/master/config.
It is important to note that when defining
what fields to parse in config.toml, the same fields must be included
in schema.sql. However, all fields with ".", must be replaced in
the with "_" in schema.sql.
*/
package config
import (
"log"
"path/filepath"
"github.com/BurntSushi/toml"
)
// Config represents config options for fields to parse and db options
type Config struct {
Title string
Parser map[string]parser
DB database `toml:"database"`
}
type parser struct {
Fields []string
}
type database struct {
Username string
Password string
IP string
Port string
DatabaseName string
}
// SetupConfig parses a toml file and log.Fatal's if it cannot parse it correctly
func (c *Config) SetupConfig(path string) {
filename, _ := filepath.Abs(path)
if _, err := toml.DecodeFile(filename, c); err != nil {
log.Fatal("SetupConfig() could not decode toml, err: ", err)
}
}