2018-04-06 10:08:38 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-04-10 06:58:38 +00:00
|
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
|
|
"git.loafle.net/commons/logging-go"
|
2018-04-06 10:08:38 +00:00
|
|
|
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"
|
2018-04-10 06:58:38 +00:00
|
|
|
oca "git.loafle.net/overflow/commons-go/annotation"
|
|
|
|
"git.loafle.net/overflow/member_gateway_rest/config"
|
2018-04-06 10:08:38 +00:00
|
|
|
"git.loafle.net/overflow/member_gateway_rest/servlet"
|
|
|
|
)
|
|
|
|
|
2018-04-10 06:58:38 +00:00
|
|
|
func NewServer(_config *config.Config) *cswf.Server {
|
2018-04-06 10:08:38 +00:00
|
|
|
serverCodec := crpj.NewServerCodec()
|
|
|
|
rpcRegistry := crr.NewRPCRegistry()
|
|
|
|
|
2018-04-10 06:58:38 +00:00
|
|
|
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)
|
|
|
|
}
|
2018-04-06 10:08:38 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:17:07 +00:00
|
|
|
webappS := &servlet.WebappServlets{}
|
2018-04-06 10:08:38 +00:00
|
|
|
webappS.ServerCodec = serverCodec
|
|
|
|
webappS.RPCInvoker = rpcRegistry
|
|
|
|
|
2018-04-10 06:58:38 +00:00
|
|
|
sh := &ServerHandlers{
|
|
|
|
ServerHandlers: *_config.ServerHandler,
|
|
|
|
Config: _config,
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:08:38 +00:00
|
|
|
sh.RegisterServlet("/webapp", webappS)
|
|
|
|
|
|
|
|
s := &cswf.Server{
|
|
|
|
ServerHandler: sh,
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|