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.
Files changed (82) hide show
  1. package/MaoServerDiscovery +0 -0
  2. package/package.json +1 -1
  3. package/.github/dependabot.yml +0 -11
  4. package/.github/workflows/codeql-analysis.yml +0 -75
  5. package/.github/workflows/docker-image.yml +0 -24
  6. package/.github/workflows/docker-publish.yml +0 -94
  7. package/.github/workflows/go.yml +0 -29
  8. package/.github/workflows/go_static.yml +0 -29
  9. package/.github/workflows/npm-publish-release.yml +0 -36
  10. package/.github/workflows/npm-publish.yml +0 -41
  11. package/Dockerfile +0 -19
  12. package/LICENSE +0 -201
  13. package/MODULES.md +0 -39
  14. package/README.md +0 -54
  15. package/bak/index.html +0 -42
  16. package/bak/receiveProcessIcmpLoopV4V6.bak +0 -73
  17. package/bak/test/test-icmp-ka-module.go +0 -297
  18. package/bak/test/test-tech.go +0 -110
  19. package/bak/using_etcd/main.go +0 -165
  20. package/cmd/api/aux-data-module.go +0 -14
  21. package/cmd/api/config-module.go +0 -11
  22. package/cmd/api/email-module.go +0 -14
  23. package/cmd/api/gateway-module.go +0 -23
  24. package/cmd/api/grpc-ka-module.go +0 -29
  25. package/cmd/api/icmp-ka-module.go +0 -26
  26. package/cmd/api/restful-server-module.go +0 -13
  27. package/cmd/api/topo-module.go +0 -31
  28. package/cmd/api/wechat-module.go +0 -18
  29. package/cmd/general_client.go +0 -366
  30. package/cmd/lib/AuxDataProcessor/aux-data-processor-module.go +0 -64
  31. package/cmd/lib/AuxDataProcessor/env-temp-processor.go +0 -63
  32. package/cmd/lib/AuxDataProcessor/env-temp-processor_test.go +0 -30
  33. package/cmd/lib/Config/config-yaml-module.go +0 -303
  34. package/cmd/lib/Config/config-yaml-module_test.go +0 -308
  35. package/cmd/lib/Email/login-auth.go +0 -35
  36. package/cmd/lib/Email/login-auth_test.go +0 -13
  37. package/cmd/lib/Email/smtp-email-module.go +0 -229
  38. package/cmd/lib/Email/smtp-email-module_test.go +0 -12
  39. package/cmd/lib/GrpcKa/grpc-detect-module.go +0 -269
  40. package/cmd/lib/GrpcKa/grpc-detect-module_test.go +0 -26
  41. package/cmd/lib/IcmpKa/icmp-detect-module.go +0 -545
  42. package/cmd/lib/IcmpKa/icmp-detect-module_test.go +0 -23
  43. package/cmd/lib/InfluxDB/influxdb-util.go +0 -72
  44. package/cmd/lib/MaoCommon/gps.go +0 -15
  45. package/cmd/lib/MaoCommon/service-registry-util.go +0 -59
  46. package/cmd/lib/MaoCommon/service-registry.go +0 -14
  47. package/cmd/lib/MaoCommon/service-registry_test.go +0 -30
  48. package/cmd/lib/MaoEnhancedGolang/smtp.go +0 -438
  49. package/cmd/lib/Restful/restful-server-impl.go +0 -87
  50. package/cmd/lib/Soap/soap-tplink-util.go +0 -186
  51. package/cmd/lib/Soap/soap-tplink-util_test.go +0 -45
  52. package/cmd/lib/Soap/tplink-gateway-module.go +0 -200
  53. package/cmd/server.go +0 -327
  54. package/go.mod +0 -38
  55. package/go.sum +0 -222
  56. package/grpc.maojianwei.com/server/discovery/api/generate_api_from_protobuf.sh +0 -1
  57. package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery.pb.go +0 -403
  58. package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery.proto +0 -35
  59. package/grpc.maojianwei.com/server/discovery/api/mao-server-discovery_grpc.pb.go +0 -207
  60. package/incubator/OnosTopoShow/onos-topo-module.go +0 -347
  61. package/incubator/Wechat/wechat-message-module.go +0 -267
  62. package/incubator/Wechat/wechat-message-module_test.go +0 -108
  63. package/main.go +0 -383
  64. package/notebook/notebook.txt +0 -8
  65. package/resource/index-email.html +0 -67
  66. package/resource/index-icmp.html +0 -41
  67. package/resource/index-onos.html +0 -38
  68. package/resource/index-server.html +0 -57
  69. package/resource/index-wechat.html +0 -64
  70. package/resource/jquery-3.6.0.min.js +0 -2
  71. package/screenshot/2-cli-output.png +0 -0
  72. package/screenshot/2-cli-parameters.png +0 -0
  73. package/screenshot/2-json-format.png +0 -0
  74. package/screenshot/2-readable-format.png +0 -0
  75. package/screenshot/client-server-mode-1.png +0 -0
  76. package/screenshot/client-server-mode-2.png +0 -0
  77. package/screenshot/client-server-mode-production.png +0 -0
  78. package/screenshot/show_using_etcd.png +0 -0
  79. package/statically_linked_compilation.sh +0 -2
  80. package/util/mao_log.go +0 -42
  81. package/util/mao_log_test.go +0 -73
  82. package/util/mao_util.go +0 -53
@@ -1,59 +0,0 @@
1
- package MaoCommon
2
-
3
- import MaoApi "MaoServerDiscovery/cmd/api"
4
-
5
- // If you add a new api, please provide a util function here for it :)
6
-
7
- // if fail, return nil
8
- func ServiceRegistryGetConfigModule() (serviceInstance MaoApi.ConfigModule) {
9
- configModule, _ := GetService(MaoApi.ConfigModuleRegisterName).(MaoApi.ConfigModule)
10
- return configModule
11
- }
12
-
13
- // if fail, return nil
14
- func ServiceRegistryGetGrpcKaModule() (serviceInstance MaoApi.GrpcKaModule) {
15
- grpcKaModule, _ := GetService(MaoApi.GrpcKaModuleRegisterName).(MaoApi.GrpcKaModule)
16
- return grpcKaModule
17
- }
18
-
19
- // if fail, return nil
20
- func ServiceRegistryGetIcmpKaModule() (serviceInstance MaoApi.IcmpKaModule) {
21
- icmpKaModule, _ := GetService(MaoApi.IcmpKaModuleRegisterName).(MaoApi.IcmpKaModule)
22
- return icmpKaModule
23
- }
24
-
25
- // if fail, return nil
26
- func ServiceRegistryGetRestfulServerModule() (serviceInstance MaoApi.RestfulServerModule) {
27
- restfulServer, _ := GetService(MaoApi.RestfulServerRegisterName).(MaoApi.RestfulServerModule)
28
- return restfulServer
29
- }
30
-
31
- // if fail, return nil
32
- func ServiceRegistryGetEmailModule() (serviceInstance MaoApi.EmailModule) {
33
- emailModule, _ := GetService(MaoApi.EmailModuleRegisterName).(MaoApi.EmailModule)
34
- return emailModule
35
- }
36
-
37
- // if fail, return nil
38
- func ServiceRegistryGetTopoModule() (serviceInstance MaoApi.TopoModule) {
39
- topoModule, _ := GetService(MaoApi.TopoModuleRegisterName).(MaoApi.TopoModule)
40
- return topoModule
41
- }
42
-
43
- // if fail, return nil
44
- func ServiceRegistryGetWechatModule() (serviceInstance MaoApi.WechatModule) {
45
- wechatModule, _ := GetService(MaoApi.WechatModuleRegisterName).(MaoApi.WechatModule)
46
- return wechatModule
47
- }
48
-
49
- // if fail, return nil
50
- func ServiceRegistryGetAuxDataModule() (serviceInstance MaoApi.AuxDataModule) {
51
- auxDataModule, _ := GetService(MaoApi.AuxDataModuleRegisterName).(MaoApi.AuxDataModule)
52
- return auxDataModule
53
- }
54
-
55
- // if fail, return nil
56
- func ServiceRegistryGetGatewayModule() (serviceInstance MaoApi.GatewayModule) {
57
- gatewayModule, _ := GetService(MaoApi.GatewayModuleRegisterName).(MaoApi.GatewayModule)
58
- return gatewayModule
59
- }
@@ -1,14 +0,0 @@
1
- package MaoCommon
2
-
3
- var (
4
- serviceRegistry = make(map[string]interface{})
5
- )
6
-
7
- func RegisterService(apiName string, serviceInstancePointer interface{}) {
8
- serviceRegistry[apiName] = serviceInstancePointer
9
- }
10
-
11
- // now: return the instance, not the pointer of the instance
12
- func GetService(apiName string) (serviceInstance interface{}) {
13
- return serviceRegistry[apiName]
14
- }
@@ -1,30 +0,0 @@
1
- package MaoCommon
2
-
3
- import (
4
- MaoApi "MaoServerDiscovery/cmd/api"
5
- "MaoServerDiscovery/cmd/lib/Restful"
6
- "testing"
7
- )
8
-
9
- func TestServiceRegistry_GetService(t *testing.T) {
10
- restfulServer := &Restful.RestfulServerImpl{}
11
- RegisterService(MaoApi.RestfulServerRegisterName, restfulServer)
12
-
13
- r, ok := GetService(MaoApi.RestfulServerRegisterName).(MaoApi.RestfulServerModule)
14
- if r != nil && ok {
15
- } else {
16
- t.Errorf("Fail case: get RestfulServerRegisterName and cast to RestfulServerModule, %v, %v", r, ok)
17
- }
18
-
19
- c, ok := GetService(MaoApi.RestfulServerRegisterName).(MaoApi.ConfigModule)
20
- if c == nil && !ok {
21
- } else {
22
- t.Errorf("Fail case: get RestfulServerRegisterName and cast to ConfigModule, %v, %v", c, ok)
23
- }
24
-
25
- ccc, ok := GetService(MaoApi.ConfigModuleRegisterName).(MaoApi.ConfigModule)
26
- if ccc == nil && !ok {
27
- } else {
28
- t.Errorf("Fail case: get ConfigModuleRegisterName and cast to ConfigModule, %v, %v", ccc, ok)
29
- }
30
- }
@@ -1,438 +0,0 @@
1
- package MaoEnhancedGolang
2
-
3
- // Copyright 2010 The Go Authors. All rights reserved.
4
- // Use of this source code is governed by a BSD-style
5
- // license that can be found in the LICENSE file.
6
-
7
- // Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321.
8
- // It also implements the following extensions:
9
- // 8BITMIME RFC 1652
10
- // AUTH RFC 2554
11
- // STARTTLS RFC 3207
12
- // Additional extensions may be handled by clients.
13
- //
14
- // The smtp package is frozen and is not accepting new features.
15
- // Some external packages provide more functionality. See:
16
- //
17
- // https://godoc.org/?q=smtp
18
- //package smtp
19
-
20
- import (
21
- "crypto/tls"
22
- "encoding/base64"
23
- "errors"
24
- "fmt"
25
- "io"
26
- "net"
27
- "net/smtp"
28
- "net/textproto"
29
- "strings"
30
- )
31
-
32
- // A Client represents a client connection to an SMTP server.
33
- type Client struct {
34
- // Text is the textproto.Conn used by the Client. It is exported to allow for
35
- // clients to add extensions.
36
- Text *textproto.Conn
37
- // keep a reference to the connection so it can be used to create a TLS
38
- // connection later
39
- conn net.Conn
40
- // whether the Client is using TLS
41
- tls bool
42
- serverName string
43
- // map of supported extensions
44
- ext map[string]string
45
- // supported auth mechanisms
46
- auth []string
47
- localName string // the name to use in HELO/EHLO
48
- didHello bool // whether we've said HELO/EHLO
49
- helloError error // the error from the hello
50
- }
51
-
52
- // Dial returns a new Client connected to an SMTP server at addr.
53
- // The addr must include a port, as in "mail.example.com:smtp".
54
- func Dial(addr string) (*Client, error) {
55
- conn, err := net.Dial("tcp", addr)
56
- if err != nil {
57
- return nil, err
58
- }
59
- host, _, _ := net.SplitHostPort(addr)
60
- return NewClient(conn, host)
61
- }
62
-
63
- // NewClient returns a new Client using an existing connection and host as a
64
- // server name to be used when authenticating.
65
- func NewClient(conn net.Conn, host string) (*Client, error) {
66
- text := textproto.NewConn(conn)
67
- _, _, err := text.ReadResponse(220)
68
- if err != nil {
69
- text.Close()
70
- return nil, err
71
- }
72
- c := &Client{Text: text, conn: conn, serverName: host, localName: "localhost"}
73
- _, c.tls = conn.(*tls.Conn)
74
- return c, nil
75
- }
76
-
77
- // Close closes the connection.
78
- func (c *Client) Close() error {
79
- return c.Text.Close()
80
- }
81
-
82
- // hello runs a hello exchange if needed.
83
- func (c *Client) hello() error {
84
- if !c.didHello {
85
- c.didHello = true
86
- err := c.ehlo()
87
- if err != nil {
88
- c.helloError = c.helo()
89
- }
90
- }
91
- return c.helloError
92
- }
93
-
94
- // Hello sends a HELO or EHLO to the server as the given host name.
95
- // Calling this method is only necessary if the client needs control
96
- // over the host name used. The client will introduce itself as "localhost"
97
- // automatically otherwise. If Hello is called, it must be called before
98
- // any of the other methods.
99
- func (c *Client) Hello(localName string) error {
100
- if err := validateLine(localName); err != nil {
101
- return err
102
- }
103
- if c.didHello {
104
- return errors.New("smtp: Hello called after other methods")
105
- }
106
- c.localName = localName
107
- return c.hello()
108
- }
109
-
110
- // cmd is a convenience function that sends a command and returns the response
111
- func (c *Client) cmd(expectCode int, format string, args ...any) (int, string, error) {
112
- id, err := c.Text.Cmd(format, args...)
113
- if err != nil {
114
- return 0, "", err
115
- }
116
- c.Text.StartResponse(id)
117
- defer c.Text.EndResponse(id)
118
- code, msg, err := c.Text.ReadResponse(expectCode)
119
- return code, msg, err
120
- }
121
-
122
- // helo sends the HELO greeting to the server. It should be used only when the
123
- // server does not support ehlo.
124
- func (c *Client) helo() error {
125
- c.ext = nil
126
- _, _, err := c.cmd(250, "HELO %s", c.localName)
127
- return err
128
- }
129
-
130
- // ehlo sends the EHLO (extended hello) greeting to the server. It
131
- // should be the preferred greeting for servers that support it.
132
- func (c *Client) ehlo() error {
133
- _, msg, err := c.cmd(250, "EHLO %s", c.localName)
134
- if err != nil {
135
- return err
136
- }
137
- ext := make(map[string]string)
138
- extList := strings.Split(msg, "\n")
139
- if len(extList) > 1 {
140
- extList = extList[1:]
141
- for _, line := range extList {
142
- k, v, _ := strings.Cut(line, " ")
143
- ext[k] = v
144
- }
145
- }
146
- if mechs, ok := ext["AUTH"]; ok {
147
- c.auth = strings.Split(mechs, " ")
148
- }
149
- c.ext = ext
150
- return err
151
- }
152
-
153
- // StartTLS sends the STARTTLS command and encrypts all further communication.
154
- // Only servers that advertise the STARTTLS extension support this function.
155
- func (c *Client) StartTLS(config *tls.Config) error {
156
- if err := c.hello(); err != nil {
157
- return err
158
- }
159
- _, _, err := c.cmd(220, "STARTTLS")
160
- if err != nil {
161
- return err
162
- }
163
- c.conn = tls.Client(c.conn, config)
164
- c.Text = textproto.NewConn(c.conn)
165
- c.tls = true
166
- return c.ehlo()
167
- }
168
-
169
- // TLSConnectionState returns the client's TLS connection state.
170
- // The return values are their zero values if StartTLS did
171
- // not succeed.
172
- func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) {
173
- tc, ok := c.conn.(*tls.Conn)
174
- if !ok {
175
- return
176
- }
177
- return tc.ConnectionState(), true
178
- }
179
-
180
- // Verify checks the validity of an email address on the server.
181
- // If Verify returns nil, the address is valid. A non-nil return
182
- // does not necessarily indicate an invalid address. Many servers
183
- // will not verify addresses for security reasons.
184
- func (c *Client) Verify(addr string) error {
185
- if err := validateLine(addr); err != nil {
186
- return err
187
- }
188
- if err := c.hello(); err != nil {
189
- return err
190
- }
191
- _, _, err := c.cmd(250, "VRFY %s", addr)
192
- return err
193
- }
194
-
195
- // Auth authenticates a client using the provided authentication mechanism.
196
- // A failed authentication closes the connection.
197
- // Only servers that advertise the AUTH extension support this function.
198
- func (c *Client) Auth(a smtp.Auth) error {
199
- if err := c.hello(); err != nil {
200
- return err
201
- }
202
- encoding := base64.StdEncoding
203
- mech, resp, err := a.Start(&smtp.ServerInfo{c.serverName, c.tls, c.auth})
204
- if err != nil {
205
- c.Quit()
206
- return err
207
- }
208
- resp64 := make([]byte, encoding.EncodedLen(len(resp)))
209
- encoding.Encode(resp64, resp)
210
- code, msg64, err := c.cmd(0, strings.TrimSpace(fmt.Sprintf("AUTH %s %s", mech, resp64)))
211
- for err == nil {
212
- var msg []byte
213
- switch code {
214
- case 334:
215
- msg, err = encoding.DecodeString(msg64)
216
- case 235:
217
- // the last message isn't base64 because it isn't a challenge
218
- msg = []byte(msg64)
219
- default:
220
- err = &textproto.Error{Code: code, Msg: msg64}
221
- }
222
- if err == nil {
223
- resp, err = a.Next(msg, code == 334)
224
- }
225
- if err != nil {
226
- // abort the AUTH
227
- c.cmd(501, "*")
228
- c.Quit()
229
- break
230
- }
231
- if resp == nil {
232
- break
233
- }
234
- resp64 = make([]byte, encoding.EncodedLen(len(resp)))
235
- encoding.Encode(resp64, resp)
236
- code, msg64, err = c.cmd(0, string(resp64))
237
- }
238
- return err
239
- }
240
-
241
- // Mail issues a MAIL command to the server using the provided email address.
242
- // If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME
243
- // parameter. If the server supports the SMTPUTF8 extension, Mail adds the
244
- // SMTPUTF8 parameter.
245
- // This initiates a mail transaction and is followed by one or more Rcpt calls.
246
- func (c *Client) Mail(from string) error {
247
- if err := validateLine(from); err != nil {
248
- return err
249
- }
250
- if err := c.hello(); err != nil {
251
- return err
252
- }
253
- cmdStr := "MAIL FROM:<%s>"
254
- if c.ext != nil {
255
- if _, ok := c.ext["8BITMIME"]; ok {
256
- cmdStr += " BODY=8BITMIME"
257
- }
258
- if _, ok := c.ext["SMTPUTF8"]; ok {
259
- cmdStr += " SMTPUTF8"
260
- }
261
- }
262
- _, _, err := c.cmd(250, cmdStr, from)
263
- return err
264
- }
265
-
266
- // Rcpt issues a RCPT command to the server using the provided email address.
267
- // A call to Rcpt must be preceded by a call to Mail and may be followed by
268
- // a Data call or another Rcpt call.
269
- func (c *Client) Rcpt(to string) error {
270
- if err := validateLine(to); err != nil {
271
- return err
272
- }
273
- _, _, err := c.cmd(25, "RCPT TO:<%s>", to)
274
- return err
275
- }
276
-
277
- type dataCloser struct {
278
- c *Client
279
- io.WriteCloser
280
- }
281
-
282
- func (d *dataCloser) Close() error {
283
- d.WriteCloser.Close()
284
- _, _, err := d.c.Text.ReadResponse(250)
285
- return err
286
- }
287
-
288
- // Data issues a DATA command to the server and returns a writer that
289
- // can be used to write the mail headers and body. The caller should
290
- // close the writer before calling any more methods on c. A call to
291
- // Data must be preceded by one or more calls to Rcpt.
292
- func (c *Client) Data() (io.WriteCloser, error) {
293
- _, _, err := c.cmd(354, "DATA")
294
- if err != nil {
295
- return nil, err
296
- }
297
- return &dataCloser{c, c.Text.DotWriter()}, nil
298
- }
299
-
300
- var testHookStartTLS func(*tls.Config) // nil, except for tests
301
-
302
- // SendMail connects to the server at addr, switches to TLS if
303
- // possible, authenticates with the optional mechanism a if possible,
304
- // and then sends an email from address from, to addresses to, with
305
- // message msg.
306
- // The addr must include a port, as in "mail.example.com:smtp".
307
- //
308
- // The addresses in the to parameter are the SMTP RCPT addresses.
309
- //
310
- // The msg parameter should be an RFC 822-style email with headers
311
- // first, a blank line, and then the message body. The lines of msg
312
- // should be CRLF terminated. The msg headers should usually include
313
- // fields such as "From", "To", "Subject", and "Cc". Sending "Bcc"
314
- // messages is accomplished by including an email address in the to
315
- // parameter but not including it in the msg headers.
316
- //
317
- // The SendMail function and the net/smtp package are low-level
318
- // mechanisms and provide no support for DKIM signing, MIME
319
- // attachments (see the mime/multipart package), or other mail
320
- // functionality. Higher-level packages exist outside of the standard
321
- // library.
322
- func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte, tlsConfig *tls.Config) error {
323
- if err := validateLine(from); err != nil {
324
- return err
325
- }
326
- for _, recp := range to {
327
- if err := validateLine(recp); err != nil {
328
- return err
329
- }
330
- }
331
- c, err := Dial(addr)
332
- if err != nil {
333
- return err
334
- }
335
- defer c.Close()
336
- if err = c.hello(); err != nil {
337
- return err
338
- }
339
- if ok, _ := c.Extension("STARTTLS"); ok {
340
- config := tlsConfig
341
- if config == nil {
342
- config = &tls.Config{ServerName: c.serverName}
343
- } else {
344
- config.ServerName = c.serverName
345
- }
346
- if testHookStartTLS != nil {
347
- testHookStartTLS(config)
348
- }
349
- if err = c.StartTLS(config); err != nil {
350
- return err
351
- }
352
- }
353
- if a != nil && c.ext != nil {
354
- if _, ok := c.ext["AUTH"]; !ok {
355
- return errors.New("smtp: server doesn't support AUTH")
356
- }
357
- if err = c.Auth(a); err != nil {
358
- return err
359
- }
360
- }
361
- if err = c.Mail(from); err != nil {
362
- return err
363
- }
364
- for _, addr := range to {
365
- if err = c.Rcpt(addr); err != nil {
366
- return err
367
- }
368
- }
369
- w, err := c.Data()
370
- if err != nil {
371
- return err
372
- }
373
- _, err = w.Write(msg)
374
- if err != nil {
375
- return err
376
- }
377
- err = w.Close()
378
- if err != nil {
379
- return err
380
- }
381
- return c.Quit()
382
- }
383
-
384
- // Extension reports whether an extension is support by the server.
385
- // The extension name is case-insensitive. If the extension is supported,
386
- // Extension also returns a string that contains any parameters the
387
- // server specifies for the extension.
388
- func (c *Client) Extension(ext string) (bool, string) {
389
- if err := c.hello(); err != nil {
390
- return false, ""
391
- }
392
- if c.ext == nil {
393
- return false, ""
394
- }
395
- ext = strings.ToUpper(ext)
396
- param, ok := c.ext[ext]
397
- return ok, param
398
- }
399
-
400
- // Reset sends the RSET command to the server, aborting the current mail
401
- // transaction.
402
- func (c *Client) Reset() error {
403
- if err := c.hello(); err != nil {
404
- return err
405
- }
406
- _, _, err := c.cmd(250, "RSET")
407
- return err
408
- }
409
-
410
- // Noop sends the NOOP command to the server. It does nothing but check
411
- // that the connection to the server is okay.
412
- func (c *Client) Noop() error {
413
- if err := c.hello(); err != nil {
414
- return err
415
- }
416
- _, _, err := c.cmd(250, "NOOP")
417
- return err
418
- }
419
-
420
- // Quit sends the QUIT command and closes the connection to the server.
421
- func (c *Client) Quit() error {
422
- if err := c.hello(); err != nil {
423
- return err
424
- }
425
- _, _, err := c.cmd(221, "QUIT")
426
- if err != nil {
427
- return err
428
- }
429
- return c.Text.Close()
430
- }
431
-
432
- // validateLine checks to see if a line has CR or LF as per RFC 5321
433
- func validateLine(line string) error {
434
- if strings.ContainsAny(line, "\n\r") {
435
- return errors.New("smtp: A line must not contain CR or LF")
436
- }
437
- return nil
438
- }
@@ -1,87 +0,0 @@
1
- package Restful
2
-
3
- import (
4
- "MaoServerDiscovery/util"
5
- "fmt"
6
- "github.com/gin-gonic/gin"
7
- )
8
-
9
- const (
10
- MODULE_NAME = "Restful-Server-module"
11
- )
12
-
13
- type RestfulServerImpl struct {
14
- restful *gin.Engine
15
-
16
- serviceAddr string
17
-
18
- uiPageLinks []string
19
- getApiLinks []string
20
- postApiLinks []string
21
- }
22
-
23
- func (r *RestfulServerImpl) InitRestfulServer() {
24
- gin.SetMode(gin.ReleaseMode)
25
- r.restful = gin.Default()
26
-
27
- r.restful.LoadHTMLGlob("resource/*")
28
- r.restful.Static("/static/", "resource")
29
-
30
- r.restful.GET("/", r.showApiListPage)
31
-
32
- // not need to initiate []string
33
- }
34
-
35
- func (r *RestfulServerImpl) RegisterUiPage(relativePath string, handlers ...gin.HandlerFunc) {
36
- r.restful.GET(relativePath, handlers...)
37
- r.uiPageLinks = append(r.uiPageLinks, relativePath)
38
- }
39
-
40
- func (r *RestfulServerImpl) RegisterGetApi(relativePath string, handlers ...gin.HandlerFunc) {
41
- r.restful.GET(relativePath, handlers...)
42
- r.getApiLinks = append(r.getApiLinks, relativePath)
43
- }
44
-
45
- func (r *RestfulServerImpl) RegisterPostApi(relativePath string, handlers ...gin.HandlerFunc) {
46
- r.restful.POST(relativePath, handlers...)
47
- r.postApiLinks = append(r.postApiLinks, relativePath)
48
- }
49
-
50
- func (r *RestfulServerImpl) showApiListPage(c *gin.Context) {
51
- htmlHead := `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>MaoServiceDiscovery: URLs</title></head><body>`
52
-
53
- ret := "UI:<br/>"
54
- for _, v := range r.uiPageLinks {
55
- ret = fmt.Sprintf(`%s<a href="%s">%s</a><br/>`, ret, v, v)
56
- }
57
-
58
- ret += "<br/>GET API:<br/>"
59
- for _, v := range r.getApiLinks {
60
- ret = fmt.Sprintf(`%s<a href="%s">%s</a><br/>`, ret, v, v)
61
- }
62
-
63
- ret += "<br/>POST API:<br/>"
64
- for _, v := range r.postApiLinks {
65
- ret = fmt.Sprintf("%s%s<br/>", ret, v)
66
- }
67
-
68
- htmlTail := `</body></html>`
69
-
70
- ret = fmt.Sprintf("%s%s%s", htmlHead, ret, htmlTail)
71
-
72
- //c.String(200, ret)
73
- c.Data(200, "text/html; charset=utf-8", []byte(ret))
74
- }
75
-
76
- func (r *RestfulServerImpl) startRestfulServer() {
77
- util.MaoLogM(util.INFO, MODULE_NAME, "Starting web show %s ...", r.serviceAddr)
78
- err := r.restful.Run(r.serviceAddr)
79
- if err != nil {
80
- util.MaoLogM(util.ERROR, MODULE_NAME, "Fail to run rest server, %s", err)
81
- }
82
- }
83
-
84
- func (r *RestfulServerImpl) StartRestfulServerDaemon(webAddr string) {
85
- r.serviceAddr = webAddr
86
- go r.startRestfulServer()
87
- }