probe/server/server.go

51 lines
1.2 KiB
Go
Raw Normal View History

2018-08-23 09:21:48 +00:00
package server
import (
od "git.loafle.net/overflow/di-go"
olog "git.loafle.net/overflow/log-go"
orpj "git.loafle.net/overflow/rpc-go/protocol/json"
orr "git.loafle.net/overflow/rpc-go/registry"
ossw "git.loafle.net/overflow/server-go/socket/web"
"git.loafle.net/overflow_scanner/probe/annotation"
2018-08-30 06:35:03 +00:00
"git.loafle.net/overflow_scanner/probe/discovery"
2018-09-04 10:09:15 +00:00
"git.loafle.net/overflow_scanner/probe/internal/pubsub"
2018-08-23 09:21:48 +00:00
// For service
_ "git.loafle.net/overflow_scanner/probe/service"
)
func New() *ossw.Server {
rpcServerCodec := orpj.NewServerCodec()
2018-09-04 10:09:15 +00:00
_pubsub := pubsub.New(10)
2018-08-23 09:21:48 +00:00
2018-09-04 07:07:45 +00:00
od.RegisterSingletonByName("Discoverer", discovery.Instance())
2018-09-04 10:09:15 +00:00
od.RegisterSingletonByName("PubSub", _pubsub)
2018-08-30 06:35:03 +00:00
2018-08-23 09:21:48 +00:00
services, err := od.GetInstancesByAnnotationType(annotation.ServiceAnnotationType)
if nil != err {
olog.Logger().Panic(err.Error())
}
rpcRegistry := orr.NewRPCRegistry()
rpcRegistry.RegisterServices(services...)
ss := &ScannerServlets{}
ss.RPCInvoker = rpcRegistry
ss.RPCServerCodec = rpcServerCodec
2018-09-04 10:09:15 +00:00
ss.PubSub = _pubsub
2018-08-23 09:21:48 +00:00
sh := &ServerHandlers{}
sh.Name = "Probe"
sh.Services = services
2018-09-04 10:09:15 +00:00
sh.PubSub = _pubsub
2018-08-23 09:21:48 +00:00
2018-09-01 06:07:15 +00:00
sh.RegisterServlet("/scanner", ss)
2018-08-23 09:21:48 +00:00
s := &ossw.Server{
ServerHandler: sh,
}
return s
}