overflow_discovery/server/server.go
crusader 9589b92095 ing
2018-03-23 01:11:03 +09:00

48 lines
1.2 KiB
Go

package server
import (
"reflect"
cdr "git.loafle.net/commons_go/di/registry"
"git.loafle.net/commons_go/logging"
crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/server"
ooca "git.loafle.net/overflow/overflow_commons_go/annotation"
oods "git.loafle.net/overflow/overflow_discovery/service"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
oopcService "git.loafle.net/overflow/overflow_probe_container/service"
)
func New(pidPath string) server.Server {
var (
services []interface{}
probeService *oopcService.ProbeService
err error
)
oods.InitService()
rpcRegistry := crr.NewRPCRegistry()
if services, err = cdr.GetInstancesByAnnotationName(ooca.ServiceTag); nil != err {
logging.Logger().Panic(err)
}
for _, s := range services {
rpcRegistry.RegisterService(s, "")
}
if _probeService, err := cdr.GetInstance(reflect.TypeOf((*oopcService.ProbeService)(nil))); nil != err {
logging.Logger().Panic(err)
} else {
probeService = _probeService.(*oopcService.ProbeService)
}
rpcSH := oopcs.NewRPCServletHandler(rpcRegistry)
socketHandler := newSocketHandler(rpcSH, probeService)
sh := newServerHandler(pidPath, socketHandler)
s := oopcs.New(sh)
return s
}