-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
40 lines (33 loc) · 915 Bytes
/
configuration.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 helpers
import (
"log"
"github.com/tkanos/gonfig"
)
// Configuration type to read configuration file
type Configuration struct {
IP string
Port int
ConnString string
}
var configuration Configuration
var initialized = false
// GetConnString function. Gets the configuration string of MySQL from a given json formated file
func GetConnString(configFileName string) string {
loadConfig(configFileName)
return configuration.ConnString
}
func loadConfig(configFileName string) {
// get Configuration
if !initialized {
err := gonfig.GetConf(configFileName, &configuration)
if err != nil {
log.Fatalf("Error loading file %s: %s", configFileName, err)
}
initialized = true
}
}
// GetIP function gets the ip of the configurated MySQL database from a given json formated file
func GetIP(configFileName string) string {
loadConfig(configFileName)
return configuration.IP
}