-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (39 loc) · 1.03 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
45
46
package Faucet
import (
"github.com/json-iterator/go"
"github.com/proximax-storage/xpx-catapult-faucet/utils"
"io/ioutil"
"os"
"strconv"
)
var (
json = jsoniter.ConfigCompatibleWithStandardLibrary
Config ConfigData
)
func LoadConfig(file *string) (*ConfigData, error) {
// Open our jsonFile
jsonFile, err := os.Open(*file)
// if we os.Open returns an error then handle it
if err != nil {
return nil, err
}
utils.Logger(0, "Loading config from: ./resources/rest.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
return nil, err
}
// we unmarshal our byteArray which contains our
// jsonFile's content into 'ConfigData' which we defined above
err = json.Unmarshal(byteValue, &Config)
if err != nil {
return nil, err
}
return &Config, nil
}
func (c *ConfigData) FormatServer() string {
port := strconv.Itoa(c.Server.Port)
return c.Server.Host + ":" + port
}