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
|
|
|
|
|
|
|
|
sh.RegisterServlet("/", ss)
|
|
|
|
|
|
|
|
s := &ossw.Server{
|
|
|
|
ServerHandler: sh,
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|