-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (59 loc) · 1.38 KB
/
main.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
package main
import (
"context"
"fmt"
"go-echo-server/config"
"go-echo-server/datagram"
"go-echo-server/handler"
"go-echo-server/server"
"golang.org/x/sync/errgroup"
)
type connect struct {
servers []server.Server
handlers []handler.Handler
}
func (ct connect) run() error {
g, _ := errgroup.WithContext(context.Background())
for _, server := range ct.servers {
server := server
g.Go(func() error {
return server.Listen(func(data datagram.Datagram) {
for _, hand := range ct.handlers {
go hand.Handle(data)
}
})
})
}
if err := g.Wait(); err != nil {
return err
}
return nil
}
func main() {
cfg, err := config.Get()
if err != nil {
panic(fmt.Errorf("配置读取错误, %+v", err))
}
ct := connect{
[]server.Server{
server.NewUDPServer(cfg.SERVER.UDP.PORT),
server.NewHTTPServer(cfg.SERVER.HTTP.PORT),
server.NewMqttServer(cfg.SERVER.MQTT.PORT),
server.NewTCPServer(cfg.SERVER.TCP.PORT),
server.NewGRPCServer(cfg.SERVER.GRPC.PORT),
},
[]handler.Handler{
handler.NewLogger(),
handler.NewSLS(
cfg.HANDLER.SLS.ACCESSKEYID,
cfg.HANDLER.SLS.ACCESSKEYSECRET,
cfg.HANDLER.SLS.ENDPOINT,
cfg.HANDLER.SLS.PROJECTNAME,
cfg.HANDLER.SLS.LOGSTORENAME,
),
},
}
if err := ct.run(); err != nil {
panic(fmt.Errorf("服务关闭, %+v", err))
}
}