From c78d3b60ea1b0c2712e77b28e41033c4dcba4ac3 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 16 Mar 2018 16:46:31 +0900 Subject: [PATCH] ing --- commons/annotation/service.go | 22 ++++++++++++++++++++++ glide.yaml | 1 + server/server.go | 13 +++++++++++-- service/ContainerService.go | 12 ++++++++++++ service/DiscoveryService.go | 9 +++++++++ service/service.go | 12 +++++------- 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 commons/annotation/service.go diff --git a/commons/annotation/service.go b/commons/annotation/service.go new file mode 100644 index 0000000..f473335 --- /dev/null +++ b/commons/annotation/service.go @@ -0,0 +1,22 @@ +package annotation + +// @Service() +// inherit @Component +import ( + "reflect" + + cda "git.loafle.net/commons_go/di/annotation" + cdia "git.loafle.net/commons_go/di/injection/annotation" +) + +const ( + ServiceTag = "@overFlow:Service" +) + +func init() { + cda.RegisterAnnotation(ServiceTag, reflect.TypeOf((*Service)(nil))) +} + +type Service struct { + cdia.Component +} diff --git a/glide.yaml b/glide.yaml index cf2b893..7fe304d 100644 --- a/glide.yaml +++ b/glide.yaml @@ -7,3 +7,4 @@ import: - package: git.loafle.net/commons_go/server - package: git.loafle.net/commons_go/rpc - package: gopkg.in/natefinch/npipe.v2 +- package: git.loafle.net/commons_go/di diff --git a/server/server.go b/server/server.go index d93c049..2bcbf9c 100644 --- a/server/server.go +++ b/server/server.go @@ -1,15 +1,24 @@ package server import ( + cdr "git.loafle.net/commons_go/di/registry" crr "git.loafle.net/commons_go/rpc/registry" "git.loafle.net/commons_go/server" - "git.loafle.net/overflow/overflow_discovery/service" + oodca "git.loafle.net/overflow/overflow_discovery/commons/annotation" + oods "git.loafle.net/overflow/overflow_discovery/service" oopcs "git.loafle.net/overflow/overflow_probe_container/server" ) func New(pidPath string) server.Server { + oods.InitService() + rpcRegistry := crr.NewRPCRegistry() - service.RegisterRPC(rpcRegistry) + + services := cdr.GetInstancesByAnnotationName(oodca.ServiceTag) + + for _, s := range services { + rpcRegistry.RegisterService(s, "") + } rpcSH := oopcs.NewRPCServletHandler(rpcRegistry) socketHandler := newSocketHandler(rpcSH) diff --git a/service/ContainerService.go b/service/ContainerService.go index 287ebd2..e643016 100644 --- a/service/ContainerService.go +++ b/service/ContainerService.go @@ -1,6 +1,18 @@ package service +import ( + "reflect" + + cda "git.loafle.net/commons_go/di/annotation" + cdr "git.loafle.net/commons_go/di/registry" +) + +func init() { + cdr.RegisterType(reflect.TypeOf((*ContainerService)(nil))) +} + type ContainerService struct { + cda.TypeAnnotation `annotation:"@overFlow:Service()"` } func (cs *ContainerService) State() (bool, error) { diff --git a/service/DiscoveryService.go b/service/DiscoveryService.go index c65bc99..a8e5c62 100644 --- a/service/DiscoveryService.go +++ b/service/DiscoveryService.go @@ -1,11 +1,20 @@ package service import ( + "reflect" + + cda "git.loafle.net/commons_go/di/annotation" + cdr "git.loafle.net/commons_go/di/registry" discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" "git.loafle.net/overflow/overflow_discovery/discovery" ) +func init() { + cdr.RegisterType(reflect.TypeOf((*DiscoveryService)(nil))) +} + type DiscoveryService struct { + cda.TypeAnnotation `annotation:"@overFlow:Service()"` } func (ds *DiscoveryService) DiscoverZone(requesterID string, dz *discoveryM.DiscoveryZone) error { diff --git a/service/service.go b/service/service.go index 1e7e2b8..fb7d721 100644 --- a/service/service.go +++ b/service/service.go @@ -1,10 +1,8 @@ package service -import ( - crr "git.loafle.net/commons_go/rpc/registry" -) - -func RegisterRPC(rpcRegistry crr.RPCRegistry) { - rpcRegistry.RegisterService(&ContainerService{}, "") - rpcRegistry.RegisterService(&DiscoveryService{}, "") +func InitService() { +} + +func DestroyService() { + }