-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.go
More file actions
executable file
·115 lines (95 loc) · 2.8 KB
/
Copy pathlib.go
File metadata and controls
executable file
·115 lines (95 loc) · 2.8 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package config
import (
"blvchain/core/logger"
"encoding/json"
"fmt"
"os"
"strconv"
"github.com/joho/godotenv"
)
func pathMaker(fileName string) string {
return CONFIG_FILE_PATH + fileName
}
// Get env from .env file in /config and return one value of the key
func GetEnv(key string) string {
err := godotenv.Load(pathMaker(".env"))
if err != nil {
logger.INTERNAL_LOGGER.Println("Error in reading '.env' file")
fmt.Println("Error: see log/internal folder for details.")
}
return os.Getenv(key)
}
func GetDeliumConfigFile() Delium_json_config {
file, err := os.Open(pathMaker("delium_config.json"))
if err != nil {
logger.INTERNAL_LOGGER.Println("Error opening 'delium_config.json' file")
fmt.Println("Error: see log/internal folder for details.")
}
defer file.Close()
var jsonConfig Delium_json_config
decoder := json.NewDecoder(file)
if err := decoder.Decode(&jsonConfig); err != nil {
logger.INTERNAL_LOGGER.Println("Error decoding 'delium_config.json'")
fmt.Println("Error: see log/internal folder for details.")
}
return jsonConfig
}
func GetDnsSeedListFile() []Dns_seed_config {
file, err := os.Open(pathMaker("dns_seed.json"))
if err != nil {
logger.INTERNAL_LOGGER.Println("Error opening 'dns_seed.json' file")
fmt.Println("Error: see log/internal folder for details.")
}
defer file.Close()
var dns_seed []Dns_seed_config
decoder := json.NewDecoder(file)
if err := decoder.Decode(&dns_seed); err != nil {
logger.INTERNAL_LOGGER.Println("Error decoding 'dns_seed.json'")
fmt.Println("Error: see log/internal folder for details.")
}
return dns_seed
}
func GetApiKeyFile() map[string]bool {
file, err := os.Open(pathMaker("api_key.json"))
if err != nil {
logger.INTERNAL_LOGGER.Println("Error opening 'api_key.json' file")
fmt.Println("Error: see log/internal folder for details.")
}
defer file.Close()
var allowedClients map[string]bool
decoder := json.NewDecoder(file)
if err := decoder.Decode(&allowedClients); err != nil {
logger.INTERNAL_LOGGER.Println("Error decoding 'api_key.json'")
fmt.Println("Error: see log/internal folder for details.")
}
return allowedClients
}
func StringToInt(strNum string) int {
num, _ := strconv.Atoi(strNum)
return num
}
func StringToFloat64(strNum string) float64 {
num, _ := strconv.ParseFloat(strNum, 64)
return num
}
func DefineENV(name string, defaultValue string) string {
envVar := os.Getenv(name)
if envVar == "" {
envVar = defaultValue
}
return envVar
}
func DefineENVFloat64(name string, defaultValue float64) float64 {
envVar := os.Getenv(name)
if envVar == "" || envVar == "0" {
return defaultValue
}
return StringToFloat64(envVar)
}
func DefineENVInt(name string, defaultValue int) int {
envVar := os.Getenv(name)
if envVar == "" || envVar == "0" {
return defaultValue
}
return StringToInt(envVar)
}