/
config.go
56 lines (48 loc) · 1.26 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
47
48
49
50
51
52
53
54
55
56
package main
import (
"encoding/json"
"os"
"github.com/iotaledger/goshimmer/client"
)
// config type that defines the config structure
type configuration struct {
WebAPI string `json:"WebAPI,omitempty"`
BasicAuth client.BasicAuth `json:"basicAuth,omitempty"`
ReuseAddresses bool `json:"reuse_addresses"`
FaucetPowDifficulty int `json:"faucetPowDifficulty"`
AssetRegistryNetwork string `json:"assetRegistryNetwork"`
}
// internal variable that holds the config
var config = configuration{}
var configJSON = `{
"WebAPI": "http://127.0.0.1:8080",
"basicAuth": {
"enabled": false,
"username": "goshimmer",
"password": "goshimmer"
},
"reuse_addresses": false,
"faucetPowDifficulty": 25,
"assetRegistryNetwork": "nectar"
}`
// load the config file
func loadConfig() {
// open config file
file, err := os.Open("config.json")
if err != nil {
if !os.IsNotExist(err) {
panic(err)
}
if err = os.WriteFile("config.json", []byte(configJSON), 0o644); err != nil {
panic(err)
}
if file, err = os.Open("config.json"); err != nil {
panic(err)
}
}
defer file.Close()
// decode config file
if err = json.NewDecoder(file).Decode(&config); err != nil {
panic(err)
}
}