-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
51 lines (40 loc) · 1.08 KB
/
router.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
package hlocalrouter
import (
"github.com/drharryhe/has/common/herrors"
"github.com/drharryhe/has/common/htypes"
"github.com/drharryhe/has/core"
)
func New() *Router {
return new(Router)
}
type Router struct {
core.BaseRouter
conf LocalRouter
}
func (this *Router) Open(s core.IServer, ins core.IRouter) *herrors.Error {
err := this.BaseRouter.Open(s, ins)
if err != nil {
return err
}
this.Services = make(map[string]core.IService)
return nil
}
func (this *Router) RequestService(service string, slot string, params htypes.Map) (htypes.Any, *herrors.Error) {
s := this.Services[service]
if s == nil || s.(core.IEntity).Config().GetDisabled() {
return nil, herrors.ErrCallerInvalidRequest.New("service [%s] not available", service)
}
if s.Slot(slot) == nil {
return nil, herrors.ErrCallerInvalidRequest.New("slot [%s] not available", slot)
}
return s.Request(slot, params)
}
func (this *Router) EntityStub() *core.EntityStub {
return core.NewEntityStub(
&core.EntityStubOptions{
Owner: this,
})
}
func (this *Router) Config() core.IEntityConf {
return &this.conf
}