probe/server/server.go

46 lines
1.0 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-08-23 09:21:48 +00:00
// For service
_ "git.loafle.net/overflow_scanner/probe/service"
)
func New() *ossw.Server {
rpcServerCodec := orpj.NewServerCodec()
2018-08-30 06:35:03 +00:00
od.RegisterResource("Discoverer", discovery.Instance())
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
sh := &ServerHandlers{}
sh.Name = "Probe"
sh.Services = services
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
}