-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
49 lines (44 loc) · 933 Bytes
/
server.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
package core
import (
"github.com/fushiliang321/go-core/amqp/consumer"
"github.com/fushiliang321/go-core/consul"
"github.com/fushiliang321/go-core/exception"
"github.com/fushiliang321/go-core/rateLimit"
rpc "github.com/fushiliang321/go-core/rpc/server"
"github.com/fushiliang321/go-core/server"
"github.com/fushiliang321/go-core/task"
"sync"
)
type Server interface {
Start(wg *sync.WaitGroup)
}
var (
servers []Server
once sync.Once
)
func Register(s Server) {
servers = append(servers, s)
}
func Registers(sers []Server) {
servers = append(servers, sers...)
}
func Start() {
defer func() {
exception.Listener("core start", recover())
}()
once.Do(func() {
wg := &sync.WaitGroup{}
Registers([]Server{
consumer.Service{},
consul.Service{},
rpc.Service{},
task.Service{},
rateLimit.Service{},
server.Service{},
})
for _, ser := range servers {
ser.Start(wg)
}
wg.Wait()
})
}