This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
81 lines (64 loc) · 1.54 KB
/
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
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
package edgetest
import (
"github.com/ronaksoft/rony"
"github.com/ronaksoft/rony/edge"
dummyGateway "github.com/ronaksoft/rony/internal/gateway/dummy"
)
/*
Creation Time: 2020 - Dec - 09
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
Copyright Ronak Software Group 2020
*/
type CheckFunc func(b []byte, kv ...*rony.KeyValue) error
var (
connID uint64 = 1
)
type Server struct {
edge *edge.Server
gw *dummyGateway.Gateway
}
func NewServer(serverID string, d edge.Dispatcher) *Server {
s := &Server{}
s.edge = edge.NewServer(serverID,
edge.WithCustomDispatcher(d),
edge.WithTestGateway(edge.DummyGatewayConfig{
Exposer: func(gw *dummyGateway.Gateway) {
s.gw = gw
},
}),
)
return s
}
func (s *Server) Start() {
_ = s.edge.StartGateway()
}
func (s *Server) Shutdown() {
s.edge.Shutdown()
}
func (s *Server) RealEdge() *edge.Server {
return s.edge
}
func (s *Server) SetGlobalPreHandlers(h ...edge.Handler) {
s.edge.SetGlobalPreHandlers(h...)
}
func (s *Server) SetHandlers(constructor uint64, h ...edge.Handler) {
s.edge.SetHandler(edge.NewHandlerOptions().SetConstructor(constructor).SetHandler(h...))
}
func (s *Server) SetGlobalPostHandlers(h ...edge.Handler) {
s.edge.SetGlobalPostHandlers(h...)
}
func (s *Server) RPC() *rpcCtx {
return newRPCContext(s.gw)
}
func (s *Server) JsonRPC() *jrpcCtx {
return newJSONRPCContext(s.gw)
}
func (s *Server) REST() *restCtx {
return newRESTContext(s.gw)
}
func (s *Server) Scenario() *scenario {
return newScenario()
}