46 lines
1023 B
Go
46 lines
1023 B
Go
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"
|
|
"git.loafle.net/overflow_scanner/probe/discovery"
|
|
|
|
// For service
|
|
_ "git.loafle.net/overflow_scanner/probe/service"
|
|
)
|
|
|
|
func New() *ossw.Server {
|
|
rpcServerCodec := orpj.NewServerCodec()
|
|
|
|
od.RegisterResource("Discoverer", discovery.Instance())
|
|
|
|
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
|
|
}
|