-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (33 loc) · 1015 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
package config
import (
"fmt"
)
// FileName file name that contain a json object.
// By default filename: "config.json"
var FileName string = "config.json"
// FilePath file config path.
// By default file config path: "./"
var FilePath string = "./"
var configurator Configurator
// RegisterConfigurator a new implement of Configurator interface
func RegisterConfigurator(conf Configurator) {
configurator = conf
}
// ValidateConfiguratorRegister validate if the Configurator interfaces has been implement
func ValidateConfiguratorRegister() error {
if configurator != nil {
return nil
}
return fmt.Errorf("the implementation of the 'config.Configurator' interface has not been registered")
}
func init() {
// By default register json configurator implement.
RegisterConfigurator(JSONConfigurator{})
var err error
file := fmt.Sprintf("%v%v", FilePath, FileName)
// Load config file
err = LoadConfigFile(file)
if err != nil {
panic(fmt.Errorf("fatal error reading config file: %s", err))
}
}