-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmap_config.go
146 lines (127 loc) · 4.21 KB
/
map_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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package config
import (
"os"
"os/user"
"path/filepath"
"github.com/FleekHQ/space-daemon/core/env"
)
type mapConfig struct {
configStr map[string]string
configInt map[string]int
configBool map[string]bool
}
func NewMap(flags *Flags) Config {
configStr := make(map[string]string)
configInt := make(map[string]int)
configBool := make(map[string]bool)
usr, _ := user.Current()
// default values
configStr[LogLevel] = flags.LogLevel
configStr[SpaceStorePath] = filepath.Join(usr.HomeDir, ".fleek-space")
configStr[MountFuseDrive] = "false"
configStr[FuseDriveName] = "Space"
configInt[SpaceServerPort] = 9999
configInt[SpaceProxyServerPort] = 9998
configInt[SpaceRestProxyServerPort] = 9997
if flags.DevMode {
configStr[Ipfsaddr] = os.Getenv(env.IpfsAddr)
configStr[Ipfsnodeaddr] = os.Getenv(env.IpfsNodeAddr)
configStr[Ipfsnodepath] = os.Getenv(env.IpfsNodePath)
configStr[SpaceServicesAPIURL] = os.Getenv(env.ServicesAPIURL)
configStr[SpaceVaultAPIURL] = os.Getenv(env.VaultAPIURL)
configStr[SpaceVaultSaltSecret] = os.Getenv(env.VaultSaltSecret)
configStr[SpaceServicesHubAuthURL] = os.Getenv(env.ServicesHubAuthURL)
configStr[SpaceStorageSiteUrl] = os.Getenv(env.SpaceStorageSiteUrl)
configStr[TextileHubTarget] = os.Getenv(env.TextileHubTarget)
configStr[TextileHubMa] = os.Getenv(env.TextileHubMa)
configStr[TextileThreadsTarget] = os.Getenv(env.TextileThreadsTarget)
configStr[TextileHubGatewayUrl] = os.Getenv(env.TextileHubGatewayUrl)
configStr[TextileUserKey] = os.Getenv(env.TextileUserKey)
configStr[TextileUserSecret] = os.Getenv(env.TextileUserSecret)
if os.Getenv(env.IpfsNode) != "false" {
configBool[Ipfsnode] = true
}
} else {
configStr[Ipfsaddr] = flags.Ipfsaddr
configStr[Ipfsnodeaddr] = flags.Ipfsnodeaddr
configStr[Ipfsnodepath] = flags.Ipfsnodepath
configStr[SpaceServicesAPIURL] = flags.ServicesAPIURL
configStr[SpaceVaultAPIURL] = flags.VaultAPIURL
configStr[SpaceVaultSaltSecret] = flags.VaultSaltSecret
configStr[SpaceServicesHubAuthURL] = flags.ServicesHubAuthURL
if flags.SpaceStorageSiteUrl != "" {
configStr[SpaceStorageSiteUrl] = flags.SpaceStorageSiteUrl
}
configStr[TextileHubTarget] = flags.TextileHubTarget
configStr[TextileHubMa] = flags.TextileHubMa
configStr[TextileThreadsTarget] = flags.TextileThreadsTarget
configStr[TextileHubGatewayUrl] = flags.TextileHubGatewayUrl
configStr[TextileUserKey] = flags.TextileUserKey
configStr[TextileUserSecret] = flags.TextileUserSecret
configBool[Ipfsnode] = flags.Ipfsnode
if flags.SpaceStorePath != "" {
configStr[SpaceStorePath] = flags.SpaceStorePath
}
if flags.RpcServerPort != 0 {
configInt[SpaceServerPort] = flags.RpcServerPort
}
if flags.RpcProxyServerPort != 0 {
configInt[SpaceProxyServerPort] = flags.RpcProxyServerPort
}
if flags.RestProxyServerPort != 0 {
configInt[SpaceRestProxyServerPort] = flags.RestProxyServerPort
}
if flags.BuckdPath != "" {
configStr[BuckdPath] = flags.BuckdPath
}
if flags.BuckdApiMaAddr != "" {
configStr[BuckdApiMaAddr] = flags.BuckdApiMaAddr
}
if flags.BuckdApiProxyMaAddr != "" {
configStr[BuckdApiProxyMaAddr] = flags.BuckdApiProxyMaAddr
}
if flags.BuckdThreadsHostMaAddr != "" {
configStr[BuckdThreadsHostMaAddr] = flags.BuckdThreadsHostMaAddr
}
if flags.BuckdGatewayPort != 0 {
configInt[BuckdGatewayPort] = flags.BuckdGatewayPort
}
}
// Temp fix until we move to viper
if configStr[Ipfsaddr] == "" {
configStr[Ipfsaddr] = "/ip4/127.0.0.1/tcp/5001"
}
c := mapConfig{
configStr: configStr,
configInt: configInt,
configBool: configBool,
}
return c
}
func (m mapConfig) GetString(key string, defaultValue interface{}) string {
if val, exists := m.configStr[key]; exists {
return val
}
if stringValue, ok := defaultValue.(string); ok {
return stringValue
}
return ""
}
func (m mapConfig) GetInt(key string, defaultValue interface{}) int {
if val, exists := m.configInt[key]; exists {
return val
}
if intVal, ok := defaultValue.(int); ok {
return intVal
}
return 0
}
func (m mapConfig) GetBool(key string, defaultValue interface{}) bool {
if val, exists := m.configBool[key]; exists {
return val
}
if boolVal, ok := defaultValue.(bool); ok {
return boolVal
}
return false
}