mao-service-discovery 1.6.0-commit-2023-07-24-04-32-53.0 → 1.6.0-commit-2023-07-24-06-22-14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MaoServerDiscovery +0 -0
- package/package.json +1 -1
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/codeql-analysis.yml +0 -75
- package/.github/workflows/docker-image.yml +0 -24
- package/.github/workflows/docker-publish.yml +0 -94
- package/.github/workflows/go.yml +0 -29
- package/.github/workflows/go_static.yml +0 -29
- package/.github/workflows/npm-publish-release.yml +0 -36
- package/.github/workflows/npm-publish.yml +0 -41
- package/Dockerfile +0 -19
- package/LICENSE +0 -201
- package/MODULES.md +0 -39
- package/README.md +0 -54
- package/bak/index.html +0 -42
- package/bak/receiveProcessIcmpLoopV4V6.bak +0 -73
- package/bak/test/test-icmp-ka-module.go +0 -297
- package/bak/test/test-tech.go +0 -110
- package/bak/using_etcd/main.go +0 -165
- package/cmd/api/aux-data-module.go +0 -14
- package/cmd/api/config-module.go +0 -11
- package/cmd/api/email-module.go +0 -14
- package/cmd/api/gateway-module.go +0 -23
- package/cmd/api/grpc-ka-module.go +0 -29
- package/cmd/api/icmp-ka-module.go +0 -26
- package/cmd/api/restful-server-module.go +0 -13
- package/cmd/api/topo-module.go +0 -31
- package/cmd/api/wechat-module.go +0 -18
- package/cmd/general_client.go +0 -366
- package/cmd/lib/AuxDataProcessor/aux-data-processor-module.go +0 -64
- package/cmd/lib/AuxDataProcessor/env-temp-processor.go +0 -63
- package/cmd/lib/AuxDataProcessor/env-temp-processor_test.go +0 -30
- package/cmd/lib/Config/config-yaml-module.go +0 -303
- package/cmd/lib/Config/config-yaml-module_test.go +0 -308
- package/cmd/lib/Email/login-auth.go +0 -35
- package/cmd/lib/Email/login-auth_test.go +0 -13
- package/cmd/lib/Email/smtp-email-module.go +0 -229
- package/cmd/lib/Email/smtp-email-module_test.go +0 -12
- package/cmd/lib/GrpcKa/grpc-detect-module.go +0 -269
- package/cmd/lib/GrpcKa/grpc-detect-module_test.go +0 -26
- package/cmd/lib/IcmpKa/icmp-detect-module.go +0 -545
- package/cmd/lib/IcmpKa/icmp-detect-module_test.go +0 -23
- package/cmd/lib/InfluxDB/influxdb-util.go +0 -72
- package/cmd/lib/MaoCommon/gps.go +0 -15
- package/cmd/lib/MaoCommon/service-registry-util.go +0 -59
- package/cmd/lib/MaoCommon/service-registry.go +0 -14
- package/cmd/lib/MaoCommon/service-registry_test.go +0 -30
- package/cmd/lib/MaoEnhancedGolang/smtp.go +0 -438
- package/cmd/lib/Restful/restful-server-impl.go +0 -87
- package/cmd/lib/Soap/soap-tplink-util.go +0 -186
- package/cmd/lib/Soap/soap-tplink-util_test.go +0 -45
- package/cmd/lib/Soap/tplink-gateway-module.go +0 -200
- package/cmd/server.go +0 -327
- package/go.mod +0 -38
- package/go.sum +0 -222
- package/grpc.maojianwei.com/server/discovery/api/generate_api_from_protobuf.sh +0 -1
- package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery.pb.go +0 -403
- package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery.proto +0 -35
- package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery_grpc.pb.go +0 -207
- package/incubator/OnosTopoShow/onos-topo-module.go +0 -347
- package/incubator/Wechat/wechat-message-module.go +0 -267
- package/incubator/Wechat/wechat-message-module_test.go +0 -108
- package/main.go +0 -383
- package/notebook/notebook.txt +0 -8
- package/resource/index-email.html +0 -67
- package/resource/index-icmp.html +0 -41
- package/resource/index-onos.html +0 -38
- package/resource/index-server.html +0 -57
- package/resource/index-wechat.html +0 -64
- package/resource/jquery-3.6.0.min.js +0 -2
- package/screenshot/2-cli-output.png +0 -0
- package/screenshot/2-cli-parameters.png +0 -0
- package/screenshot/2-json-format.png +0 -0
- package/screenshot/2-readable-format.png +0 -0
- package/screenshot/client-server-mode-1.png +0 -0
- package/screenshot/client-server-mode-2.png +0 -0
- package/screenshot/client-server-mode-production.png +0 -0
- package/screenshot/show_using_etcd.png +0 -0
- package/statically_linked_compilation.sh +0 -2
- package/util/mao_log.go +0 -42
- package/util/mao_log_test.go +0 -73
- package/util/mao_util.go +0 -53
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
package Config
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"MaoServerDiscovery/util"
|
|
5
|
-
yaml "gopkg.in/yaml.v3"
|
|
6
|
-
"io/ioutil"
|
|
7
|
-
"os"
|
|
8
|
-
"strings"
|
|
9
|
-
"time"
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
const (
|
|
13
|
-
DEFAULT_CONFIG_FILE = "mao-config.yaml"
|
|
14
|
-
|
|
15
|
-
EVENT_GET = iota
|
|
16
|
-
EVENT_PUT
|
|
17
|
-
|
|
18
|
-
MODULE_NAME = "Config-YAML-module"
|
|
19
|
-
|
|
20
|
-
ERR_CODE_SUCCESS = 0
|
|
21
|
-
ERR_CODE_PATH_FORMAT = 1
|
|
22
|
-
ERR_CODE_PATH_NOT_EXIST = 2
|
|
23
|
-
ERR_CODE_PATH_TRANSIT_FAIL = 3
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
type ConfigYamlModule struct {
|
|
27
|
-
needShutdown bool
|
|
28
|
-
eventChannel chan *configEvent
|
|
29
|
-
|
|
30
|
-
configFilename string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//var (
|
|
34
|
-
// needShutdown = false
|
|
35
|
-
// eventChannel = make(chan *configEvent, 100)
|
|
36
|
-
//)
|
|
37
|
-
|
|
38
|
-
type configEvent struct {
|
|
39
|
-
eventType int
|
|
40
|
-
path string
|
|
41
|
-
data interface{}
|
|
42
|
-
result chan eventResult
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type eventResult struct {
|
|
46
|
-
errCode int
|
|
47
|
-
result interface{}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
func (C *ConfigYamlModule) saveConfig(config map[string]interface{}) error {
|
|
51
|
-
data, _ := yaml.Marshal(config)
|
|
52
|
-
return ioutil.WriteFile(C.configFilename, data, 0666)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
func (C *ConfigYamlModule) loadConfig() (map[string]interface{}, error) {
|
|
56
|
-
|
|
57
|
-
config := make(map[string]interface{})
|
|
58
|
-
|
|
59
|
-
content, err := ioutil.ReadFile(C.configFilename)
|
|
60
|
-
if err != nil {
|
|
61
|
-
return nil, err
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
err = yaml.Unmarshal(content, &config)
|
|
65
|
-
if err != nil {
|
|
66
|
-
return nil, err
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return config, nil
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
func (C *ConfigYamlModule) GetConfig(path string) (object interface{}, errCode int) {
|
|
73
|
-
result := make(chan eventResult, 1)
|
|
74
|
-
event := &configEvent{
|
|
75
|
-
eventType: EVENT_GET,
|
|
76
|
-
path: path,
|
|
77
|
-
data: nil,
|
|
78
|
-
result: result,
|
|
79
|
-
}
|
|
80
|
-
C.eventChannel <- event
|
|
81
|
-
|
|
82
|
-
// TODO: timeout mechanism
|
|
83
|
-
ret := <-result
|
|
84
|
-
|
|
85
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "GetConfig result: %v", ret)
|
|
86
|
-
return ret.result, ret.errCode
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// PutConfig
|
|
90
|
-
// path: e.g. /version, /icmp-detect/services
|
|
91
|
-
// result: bool, true or false
|
|
92
|
-
func (C *ConfigYamlModule) PutConfig(path string, data interface{}) (success bool, errCode int) {
|
|
93
|
-
|
|
94
|
-
result := make(chan eventResult, 1)
|
|
95
|
-
event := &configEvent{
|
|
96
|
-
eventType: EVENT_PUT,
|
|
97
|
-
path: path,
|
|
98
|
-
data: data,
|
|
99
|
-
result: result,
|
|
100
|
-
}
|
|
101
|
-
C.eventChannel <- event
|
|
102
|
-
|
|
103
|
-
// TODO: timeout mechanism
|
|
104
|
-
ret := <-result
|
|
105
|
-
retBool := false
|
|
106
|
-
if ret.result != nil {
|
|
107
|
-
retBool = ret.result.(bool)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "PutConfig result: %v, %v", ret, retBool)
|
|
111
|
-
return retBool, ret.errCode
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
func (C *ConfigYamlModule) eventLoop(config map[string]interface{}) {
|
|
115
|
-
checkInterval := time.Duration(1000) * time.Millisecond
|
|
116
|
-
checkShutdownTimer := time.NewTimer(checkInterval)
|
|
117
|
-
for {
|
|
118
|
-
select {
|
|
119
|
-
case event := <-C.eventChannel:
|
|
120
|
-
|
|
121
|
-
//var posMap map[string]interface{}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
paths := strings.Split(event.path, "/")
|
|
125
|
-
if paths[0] != "" || paths[len(paths)-1] == "" {
|
|
126
|
-
event.result <- eventResult{
|
|
127
|
-
errCode: ERR_CODE_PATH_FORMAT,
|
|
128
|
-
result: nil,
|
|
129
|
-
}
|
|
130
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "format of config path is not correct.")
|
|
131
|
-
continue
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
transitPaths := paths[1 : len(paths)-1] // [a, b)
|
|
135
|
-
transitConfig := config
|
|
136
|
-
var ok = true
|
|
137
|
-
|
|
138
|
-
var missPos int
|
|
139
|
-
var tmpPath string
|
|
140
|
-
var needTerminate = false
|
|
141
|
-
for missPos, tmpPath = range transitPaths {
|
|
142
|
-
tmpObj := transitConfig[tmpPath]
|
|
143
|
-
if tmpObj == nil {
|
|
144
|
-
// We meet a nonexistent path, or the data is nil.
|
|
145
|
-
|
|
146
|
-
// Get operation: fail. (nonexistent path / data is nil)
|
|
147
|
-
// Put operation: need to create all transit path to store the data. (nonexistent path / data is nil)
|
|
148
|
-
// Put operation: if nil is in the config or the new data is nil, we will remove it or override it automatically,
|
|
149
|
-
// because it is not allowed that the config contain nil.
|
|
150
|
-
ok = false
|
|
151
|
-
break
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// if obj is not map, get (nil, false) --- if it is Put operation, you need to Put nil to delete the stale data first, then retry to Put data again.
|
|
155
|
-
// if obj is nil, get (nil, false) --- avoid by the above --- And, it is not allowed that the config contain nil.
|
|
156
|
-
// if obj is not exist, get (nil, false) --- avoid by the above
|
|
157
|
-
transitConfig, ok = tmpObj.(map[string]interface{})
|
|
158
|
-
if !ok {
|
|
159
|
-
// Put Operation: there is valid data, we can not override it automatically.
|
|
160
|
-
// Get Operation: we cannot transit forward anymore
|
|
161
|
-
event.result <- eventResult{
|
|
162
|
-
errCode: ERR_CODE_PATH_TRANSIT_FAIL,
|
|
163
|
-
result: nil,
|
|
164
|
-
}
|
|
165
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "Fail to transit the specific config path.")
|
|
166
|
-
needTerminate = true
|
|
167
|
-
break // needTerminate -> continue
|
|
168
|
-
}
|
|
169
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "%v", transitConfig)
|
|
170
|
-
}
|
|
171
|
-
if needTerminate {
|
|
172
|
-
continue
|
|
173
|
-
}
|
|
174
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "We get the transitConfig: %v, %v", transitConfig, missPos)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
switch event.eventType {
|
|
179
|
-
case EVENT_GET:
|
|
180
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "EVENT_GET, %s, %v, %v",
|
|
181
|
-
event.path, event.data, event.result)
|
|
182
|
-
|
|
183
|
-
if !ok {
|
|
184
|
-
//log.Println("out of the for, ", eventResult{
|
|
185
|
-
// errCode: ERR_CODE_PATH_TRANSIT_FAIL,
|
|
186
|
-
// result: nil,
|
|
187
|
-
//}) // event.result <-
|
|
188
|
-
event.result <- eventResult{
|
|
189
|
-
errCode: ERR_CODE_PATH_TRANSIT_FAIL,
|
|
190
|
-
result: nil,
|
|
191
|
-
}
|
|
192
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "Fail to transit the specific config path.")
|
|
193
|
-
} else {
|
|
194
|
-
result, ok := transitConfig[paths[len(paths)-1]]
|
|
195
|
-
event.result <- eventResult{
|
|
196
|
-
errCode: ERR_CODE_SUCCESS,
|
|
197
|
-
result: result,
|
|
198
|
-
}
|
|
199
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "Get operation: %v, %v", result, ok)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Old logic
|
|
203
|
-
//result, err := posMap[paths[len(paths)-1]]
|
|
204
|
-
//if err {
|
|
205
|
-
// event.result <- eventResult{
|
|
206
|
-
// errCode: ERR_CODE_SUCCESS,
|
|
207
|
-
// result: result,
|
|
208
|
-
// }
|
|
209
|
-
//} else {
|
|
210
|
-
// event.result <- eventResult{
|
|
211
|
-
// errCode: ERR_CODE_PATH_NOT_EXIST,
|
|
212
|
-
// result: nil, // result is also nil.
|
|
213
|
-
// }
|
|
214
|
-
//}
|
|
215
|
-
|
|
216
|
-
case EVENT_PUT:
|
|
217
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "EVENT_PUT, %s, %v, %v", event.path, event.data, event.result)
|
|
218
|
-
|
|
219
|
-
if !ok {
|
|
220
|
-
// Create transit path, and move transitConfig forward.
|
|
221
|
-
// If nil is in the config, we will remove it or override it automatically here.
|
|
222
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "%v, %v, %v, %v, %v", transitConfig, transitPaths, len(transitPaths), missPos, transitPaths[missPos])
|
|
223
|
-
for ; missPos < len(transitPaths); missPos++ {
|
|
224
|
-
var newMap = make(map[string]interface{})
|
|
225
|
-
transitConfig[transitPaths[missPos]] = newMap
|
|
226
|
-
transitConfig = newMap
|
|
227
|
-
}
|
|
228
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "Transit created, we get the transitConfig: %v", transitConfig)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// put nil means to delete. It is not allowed that the config contain nil.
|
|
232
|
-
if event.data == nil {
|
|
233
|
-
// todo: iterate from bottom to top, to delete empty map
|
|
234
|
-
delete(transitConfig, paths[len(paths)-1])
|
|
235
|
-
} else {
|
|
236
|
-
transitConfig[paths[len(paths)-1]] = event.data
|
|
237
|
-
}
|
|
238
|
-
event.result <- eventResult{
|
|
239
|
-
errCode: ERR_CODE_SUCCESS,
|
|
240
|
-
result: true,
|
|
241
|
-
}
|
|
242
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "After config: %v", config)
|
|
243
|
-
|
|
244
|
-
err := C.saveConfig(config)
|
|
245
|
-
if err != nil {
|
|
246
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "Fail to save config, we will lose config after reboot. (%s)", err.Error())
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Old Logic
|
|
250
|
-
//posMap[paths[len(paths)-1]] = event.data
|
|
251
|
-
//event.result <- eventResult{
|
|
252
|
-
// errCode: ERR_CODE_SUCCESS,
|
|
253
|
-
// result: true,
|
|
254
|
-
//}
|
|
255
|
-
}
|
|
256
|
-
case <-checkShutdownTimer.C:
|
|
257
|
-
util.MaoLogM(util.DEBUG, MODULE_NAME, "CheckShutdown, event queue len %d", len(C.eventChannel))
|
|
258
|
-
if C.needShutdown && len(C.eventChannel) == 0 {
|
|
259
|
-
util.MaoLogM(util.INFO, MODULE_NAME, "Exit.")
|
|
260
|
-
return
|
|
261
|
-
}
|
|
262
|
-
checkShutdownTimer.Reset(checkInterval)
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
func (C *ConfigYamlModule) RequireShutdown() {
|
|
268
|
-
C.needShutdown = true
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
func fileIsNotExist(fileName string) bool {
|
|
272
|
-
_, err := os.Stat(fileName)
|
|
273
|
-
return err != nil && os.IsNotExist(err)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
func (C *ConfigYamlModule) InitConfigModule(configFilename string) bool {
|
|
277
|
-
C.configFilename = configFilename
|
|
278
|
-
C.needShutdown = false
|
|
279
|
-
|
|
280
|
-
// support custom size for the channel.
|
|
281
|
-
if C.eventChannel == nil {
|
|
282
|
-
C.eventChannel = make(chan *configEvent, 100)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if fileIsNotExist(C.configFilename) {
|
|
287
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "config file not found, creating it.")
|
|
288
|
-
_, err := os.Create(C.configFilename)
|
|
289
|
-
if err != nil {
|
|
290
|
-
util.MaoLogM(util.ERROR, MODULE_NAME, "Fail to create config file. (%s)", err.Error())
|
|
291
|
-
return false
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
config, err := C.loadConfig()
|
|
296
|
-
if err != nil {
|
|
297
|
-
util.MaoLogM(util.ERROR, MODULE_NAME, "ConfigModule: Fail to load config, err: %s", err.Error())
|
|
298
|
-
return false
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
go C.eventLoop(config)
|
|
302
|
-
return true
|
|
303
|
-
}
|
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
package Config
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"log"
|
|
5
|
-
"os"
|
|
6
|
-
"testing"
|
|
7
|
-
"time"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
func TestConfigYamlModule_main(t *testing.T) {
|
|
11
|
-
|
|
12
|
-
log.Println(os.Args)
|
|
13
|
-
|
|
14
|
-
configModule := &ConfigYamlModule{
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if !configModule.InitConfigModule(DEFAULT_CONFIG_FILE) {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
mmm := make(map[string]interface{})
|
|
22
|
-
mmm["beijing"] = "ra11111dar"
|
|
23
|
-
mmm["intintint"] = 7181
|
|
24
|
-
mmm["fff"] = 2.525
|
|
25
|
-
|
|
26
|
-
vvv := make(map[int]interface{})
|
|
27
|
-
vvv[6666] = "radar"
|
|
28
|
-
vvv[8888] = 5511
|
|
29
|
-
vvv[7181] = 2.525
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
value, errCode := configModule.GetConfig("/qingdao/radar/freq") // ok
|
|
33
|
-
log.Printf("Put 1 %v, %v\n", value, errCode)
|
|
34
|
-
|
|
35
|
-
value, errCode = configModule.GetConfig("/qingdao/radar/name") // ok
|
|
36
|
-
log.Printf("Put 2 %v, %v\n", value, errCode)
|
|
37
|
-
|
|
38
|
-
value, errCode = configModule.GetConfig("/qingdao/name") // ok
|
|
39
|
-
log.Printf("Put 3 %v, %v\n", value, errCode)
|
|
40
|
-
|
|
41
|
-
value, errCode = configModule.GetConfig("/config/module/instance/object") // bad
|
|
42
|
-
log.Printf("Put 4 %v, %v\n", value, errCode)
|
|
43
|
-
|
|
44
|
-
value, errCode = configModule.GetConfig("/config/module/instance/mmm") // ok
|
|
45
|
-
log.Printf("Put 5 %v, %v\n", value, errCode)
|
|
46
|
-
|
|
47
|
-
value, errCode = configModule.GetConfig("/config/module/instance/vvv") // ok
|
|
48
|
-
log.Printf("Put 6 %v, %v\n", value, errCode)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
b, v := configModule.PutConfig("/qingdao/radar/freq", 118.5) // ok
|
|
52
|
-
log.Printf("Put 1 %v, %v\n", b, v)
|
|
53
|
-
|
|
54
|
-
b, v = configModule.PutConfig("/qingdao/radar/name", "qingdao") // ok
|
|
55
|
-
log.Printf("Put 2 %v, %v\n", b, v)
|
|
56
|
-
|
|
57
|
-
b, v = configModule.PutConfig("/qingdao/name", "liuting") // ok
|
|
58
|
-
log.Printf("Put 3 %v, %v\n", b, v)
|
|
59
|
-
|
|
60
|
-
b, v = configModule.PutConfig("/config/module/instance/object", configModule) // bad
|
|
61
|
-
log.Printf("Put 4 %v, %v\n", b, v)
|
|
62
|
-
|
|
63
|
-
b, v = configModule.PutConfig("/config/module/instance/mmm", mmm) // ok
|
|
64
|
-
log.Printf("Put 5 %v, %v\n", b, v)
|
|
65
|
-
|
|
66
|
-
b, v = configModule.PutConfig("/config/module/instance/vvv", vvv) // ok
|
|
67
|
-
log.Printf("Put 6 %v, %v\n", b, v)
|
|
68
|
-
|
|
69
|
-
configModule.RequireShutdown()
|
|
70
|
-
|
|
71
|
-
time.Sleep(3 * time.Second)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/*// ============================ Develop & Unit tests =============================
|
|
78
|
-
config := make(map[string]interface{})
|
|
79
|
-
tmp := make(map[string]interface{})
|
|
80
|
-
config["qingdao"] = tmp
|
|
81
|
-
|
|
82
|
-
tmp1 := make(map[string]interface{})
|
|
83
|
-
tmp["radar"] = tmp1
|
|
84
|
-
|
|
85
|
-
tmp2 := make(map[string]interface{})
|
|
86
|
-
tmp1["118.5"] = tmp2
|
|
87
|
-
|
|
88
|
-
tmp2["beijing-2"] = "qingdaoleida beijing bigmao"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//GET Unit Tests:
|
|
92
|
-
//path := "/" // ERR_CODE_PATH_FORMAT - ok
|
|
93
|
-
//path := "/qingdao" // pass - ok
|
|
94
|
-
//path := "/qingdao/" // ERR_CODE_PATH_FORMAT - ok
|
|
95
|
-
//
|
|
96
|
-
//path := "/qingdao/radar" // pass - ok
|
|
97
|
-
//path := "/qingdao/radar/" // ERR_CODE_PATH_FORMAT - ok
|
|
98
|
-
//
|
|
99
|
-
//path := "/qingdao/radar/118.5" // pass - ok
|
|
100
|
-
//path := "/qingdao/radar/118.5/" // ERR_CODE_PATH_FORMAT - ok
|
|
101
|
-
//
|
|
102
|
-
//path := "/qingdao/radar/218.5" // pass but result is nil - ok
|
|
103
|
-
//path := "/qingdao/padar/118.5" // ERR_CODE_PATH_TRANSIT_FAIL - ok
|
|
104
|
-
//
|
|
105
|
-
//path := "/qingdao/radar/118.5/beijing-2" // pass - ok
|
|
106
|
-
//path := "/qingdao/radar/118.5/beijing-2/" // ERR_CODE_PATH_FORMAT - ok
|
|
107
|
-
|
|
108
|
-
//Put Unit Tests:
|
|
109
|
-
//var newData interface{} = "bigmao radio station"
|
|
110
|
-
//path := "/qingdao" // pass - ok
|
|
111
|
-
//path := "/qingdao/radar" // pass - ok
|
|
112
|
-
//path := "/qingdao/radar/118.5" // pass - ok
|
|
113
|
-
//path := "/qingdao/radar/218.5" // pass - ok
|
|
114
|
-
//path := "/qingdao/padar/118.5" // pass and create all transit path - ok
|
|
115
|
-
//path := "/qingdao/padar/118.5/aaaa/b/1/5a" // pass and create all transit path - ok
|
|
116
|
-
|
|
117
|
-
//Put Unit Tests - nil:
|
|
118
|
-
//var newData interface{} = nil
|
|
119
|
-
//path := "/qingdao" // pass and delete all, result is an empty map - ok
|
|
120
|
-
//path := "/qingdao/radar" // pass and delete radar & 118.5 - ok
|
|
121
|
-
//path := "/qingdao/radar/118.5" // pass and delete 118.5 - ok
|
|
122
|
-
//path := "/qingdao/padar/118.5" // pass and: create all transit path, the last is an empty map of padar - ok
|
|
123
|
-
|
|
124
|
-
log.Println("Origin config: ", config)
|
|
125
|
-
|
|
126
|
-
// Mao: Design Principle: it is not allowed that the config contain nil.
|
|
127
|
-
|
|
128
|
-
paths := strings.Split(path, "/")
|
|
129
|
-
if paths[0] != "" || paths[len(paths)-1] == "" {
|
|
130
|
-
log.Println("eventResult: ", eventResult{
|
|
131
|
-
errCode: ERR_CODE_PATH_FORMAT,
|
|
132
|
-
result: nil,
|
|
133
|
-
}) // event.result <-
|
|
134
|
-
util.MaoLogM(util.WARN, MODULE_NAME, "format of config path is not correct.")
|
|
135
|
-
return // continue
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
transitPaths := paths[1 : len(paths)-1] // [a, b)
|
|
139
|
-
transitConfig := config
|
|
140
|
-
var ok = true
|
|
141
|
-
|
|
142
|
-
var missPos int
|
|
143
|
-
var tmpPath string
|
|
144
|
-
for missPos, tmpPath = range transitPaths {
|
|
145
|
-
tmpObj := transitConfig[tmpPath]
|
|
146
|
-
if tmpObj == nil {
|
|
147
|
-
// We meet a nonexistent path, or the data is nil.
|
|
148
|
-
|
|
149
|
-
// Get operation: fail. (nonexistent path / data is nil)
|
|
150
|
-
// Put operation: need to create all transit path to store the data. (nonexistent path / data is nil)
|
|
151
|
-
// Put operation: if nil is in the config or the new data is nil, we will remove it or override it automatically,
|
|
152
|
-
// because it is not allowed that the config contain nil.
|
|
153
|
-
ok = false
|
|
154
|
-
break
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// if obj is not map, get (nil, false) --- if it is Put operation, you need to Put nil to delete the stale data first, then retry to Put data again.
|
|
158
|
-
// if obj is nil, get (nil, false) --- avoid by the above --- And, it is not allowed that the config contain nil.
|
|
159
|
-
// if obj is not exist, get (nil, false) --- avoid by the above
|
|
160
|
-
transitConfig, ok = tmpObj.(map[string]interface{})
|
|
161
|
-
if !ok {
|
|
162
|
-
// Put Operation: there is valid data, we can not override it automatically.
|
|
163
|
-
// Get Operation: we cannot transit forward anymore
|
|
164
|
-
|
|
165
|
-
log.Println("in the for, ", eventResult{
|
|
166
|
-
errCode: ERR_CODE_PATH_TRANSIT_FAIL,
|
|
167
|
-
result: nil,
|
|
168
|
-
}) // event.result <-
|
|
169
|
-
return // continue
|
|
170
|
-
}
|
|
171
|
-
log.Println(transitConfig)
|
|
172
|
-
}
|
|
173
|
-
log.Println("We get the transitConfig: ", transitConfig, missPos)
|
|
174
|
-
|
|
175
|
-
//// in the Get case:
|
|
176
|
-
if !ok {
|
|
177
|
-
log.Println("out of the for, ", eventResult{
|
|
178
|
-
errCode: ERR_CODE_PATH_TRANSIT_FAIL,
|
|
179
|
-
result: nil,
|
|
180
|
-
}) // event.result <-
|
|
181
|
-
return
|
|
182
|
-
} else {
|
|
183
|
-
result, ok := transitConfig[paths[len(paths)-1]]
|
|
184
|
-
log.Println("Get operation: ", result, ok)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// in the Put case:
|
|
188
|
-
if !ok {
|
|
189
|
-
// Create transit path, and move transitConfig forward.
|
|
190
|
-
// If nil is in the config, we will remove it or override it automatically here.
|
|
191
|
-
log.Println(transitConfig, transitPaths, len(transitPaths), missPos, transitPaths[missPos])
|
|
192
|
-
for ; missPos < len(transitPaths); missPos++ {
|
|
193
|
-
var newMap = make(map[string]interface{})
|
|
194
|
-
transitConfig[transitPaths[missPos]] = newMap
|
|
195
|
-
transitConfig = newMap
|
|
196
|
-
}
|
|
197
|
-
log.Println("Transit created, we get the transitConfig: ", transitConfig)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// put nil means to delete. It is not allowed that the config contain nil.
|
|
201
|
-
if newData == nil {
|
|
202
|
-
// todo: iterate from bottom to top, to delete empty map
|
|
203
|
-
delete(transitConfig, paths[len(paths)-1])
|
|
204
|
-
} else {
|
|
205
|
-
transitConfig[paths[len(paths)-1]] = newData
|
|
206
|
-
}
|
|
207
|
-
log.Println("After config: ", config)
|
|
208
|
-
|
|
209
|
-
return
|
|
210
|
-
|
|
211
|
-
// =========================================================*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
//paths := strings.Split("/qingdao/ra1dar/118.5/beij1ing-2", "/")
|
|
228
|
-
//if paths[0] != "" || paths[len(paths)-1] == "" {
|
|
229
|
-
// util.MaoLogM(util.WARN, MODULE_NAME, "format of config path is not correct.")
|
|
230
|
-
//}
|
|
231
|
-
//
|
|
232
|
-
//transitPaths := paths[1:len(paths)-1]
|
|
233
|
-
//transitConfig := config
|
|
234
|
-
//var ok bool
|
|
235
|
-
//for _, p := range transitPaths {
|
|
236
|
-
// tmpvar := transitConfig[p]
|
|
237
|
-
// transitConfig, ok = tmpvar.(map[string]interface{}) // can adapt nil
|
|
238
|
-
// if !ok {
|
|
239
|
-
// // todo:fail
|
|
240
|
-
// }
|
|
241
|
-
// log.Println(transitConfig)
|
|
242
|
-
//}
|
|
243
|
-
//result := transitConfig[paths[len(paths)-1]]
|
|
244
|
-
//log.Println(result)
|
|
245
|
-
//return
|
|
246
|
-
|
|
247
|
-
//if InitConfigModule("mao-config.yaml") == false {
|
|
248
|
-
// return
|
|
249
|
-
//}
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
//log.Println(len(eventChannel))
|
|
253
|
-
//go GetConfig("getPath")
|
|
254
|
-
////eventP := &configEvent{
|
|
255
|
-
//// eventType: EVENT_PUT,
|
|
256
|
-
//// path: "putPath",
|
|
257
|
-
//// data: make([]string, 3),
|
|
258
|
-
//// result: make(chan interface{}, 1),
|
|
259
|
-
////}
|
|
260
|
-
////eventChannel <- eventP
|
|
261
|
-
//
|
|
262
|
-
//log.Println(len(eventChannel))
|
|
263
|
-
//mapmap := make(map[string]interface{})
|
|
264
|
-
//mapmap["beijing-1"] = 118.5
|
|
265
|
-
//mapmap["beijing-2"] = true
|
|
266
|
-
//mapmap["beijing-3"] = "radar contact"
|
|
267
|
-
//go PutConfig("putPath", mapmap)
|
|
268
|
-
////eventG := &configEvent{
|
|
269
|
-
//// eventType: EVENT_GET,
|
|
270
|
-
//// path: "getPath",
|
|
271
|
-
//// data: nil,
|
|
272
|
-
//// result: make(chan interface{}, 1),
|
|
273
|
-
////}
|
|
274
|
-
////eventChannel <- eventG
|
|
275
|
-
//
|
|
276
|
-
//log.Println(len(eventChannel))
|
|
277
|
-
//
|
|
278
|
-
//log.Println(eventChannel)
|
|
279
|
-
//time.Sleep(3 * time.Second)
|
|
280
|
-
//RequireShutdown()
|
|
281
|
-
//time.Sleep(1000 * time.Second)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
content, _ := ioutil.ReadFile(DEFAULT_CONFIG_FILE)
|
|
286
|
-
|
|
287
|
-
var c map[string]interface{}
|
|
288
|
-
yaml.Unmarshal(content, &c)
|
|
289
|
-
fmt.Printf("%v", c)
|
|
290
|
-
|
|
291
|
-
orderer := c["orderer"].(map[string]interface{})
|
|
292
|
-
orderer2 := c["orderer"].(map[string]interface{})
|
|
293
|
-
|
|
294
|
-
delete(orderer, )
|
|
295
|
-
|
|
296
|
-
mmm := make(map[string]interface{})
|
|
297
|
-
mmm["beijing"] = "lei da yin dao"
|
|
298
|
-
mmm["xichang"] = 6858
|
|
299
|
-
(c["orderer"].(map[interface{}]interface{}))["baas"] = mmm
|
|
300
|
-
|
|
301
|
-
fmt.Printf("%v", c)
|
|
302
|
-
data, _ := yaml.Marshal(c)
|
|
303
|
-
|
|
304
|
-
fmt.Printf("%v", data)
|
|
305
|
-
ioutil.WriteFile("yamlAfter.yaml", data, 0666)
|
|
306
|
-
|
|
307
|
-
fmt.Printf("%v", data)
|
|
308
|
-
*/
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
package Email
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"errors"
|
|
5
|
-
"fmt"
|
|
6
|
-
"net/smtp"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
func AuthLOGIN(username, password string) smtp.Auth {
|
|
11
|
-
return &authLOGIN{username, password}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type authLOGIN struct {
|
|
16
|
-
username, password string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func (a *authLOGIN) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
|
20
|
-
return "LOGIN", []byte{}, nil
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
func (a *authLOGIN) Next(fromServer []byte, more bool) ([]byte, error) {
|
|
24
|
-
if more {
|
|
25
|
-
switch string(fromServer) {
|
|
26
|
-
case "Username:", "username:":
|
|
27
|
-
return []byte(a.username), nil
|
|
28
|
-
case "Password:":
|
|
29
|
-
return []byte(a.password), nil
|
|
30
|
-
default:
|
|
31
|
-
return nil, errors.New(fmt.Sprintf("Unknown message from Server: %s", fromServer))
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return nil, nil
|
|
35
|
-
}
|