46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
"git.loafle.net/commons/logging-go"
|
|
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
|
crr "git.loafle.net/commons/rpc-go/registry"
|
|
cswf "git.loafle.net/commons/server-go/web/fasthttp"
|
|
oca "git.loafle.net/overflow/commons-go/annotation"
|
|
"git.loafle.net/overflow/member_gateway_rest/config"
|
|
"git.loafle.net/overflow/member_gateway_rest/servlet"
|
|
)
|
|
|
|
func NewServer(_config *config.Config) *cswf.Server {
|
|
serverCodec := crpj.NewServerCodec()
|
|
rpcRegistry := crr.NewRPCRegistry()
|
|
|
|
services, err := cdr.GetInstancesByAnnotationType(oca.ServiceAnnotationType)
|
|
if nil != err {
|
|
logging.Logger().Panic(err)
|
|
}
|
|
|
|
for _, _service := range services {
|
|
if err := rpcRegistry.RegisterService(_service, ""); nil != err {
|
|
logging.Logger().Panic(err)
|
|
}
|
|
}
|
|
|
|
webappS := &servlet.WebappServlets{}
|
|
webappS.ServerCodec = serverCodec
|
|
webappS.RPCInvoker = rpcRegistry
|
|
|
|
sh := &ServerHandlers{
|
|
ServerHandlers: *_config.ServerHandler,
|
|
Config: _config,
|
|
}
|
|
|
|
sh.RegisterServlet("/webapp", webappS)
|
|
|
|
s := &cswf.Server{
|
|
ServerHandler: sh,
|
|
}
|
|
|
|
return s
|
|
}
|