diff --git a/server_config.go b/impl/server_config.go similarity index 57% rename from server_config.go rename to impl/server_config.go index c95dc76..0c0dac1 100644 --- a/server_config.go +++ b/impl/server_config.go @@ -1,16 +1,18 @@ -package main +package impl import ( "golang.org/x/net/context" pb "loafle.com/overflow/crawler_go/grpc" + "loafle.com/overflow/crawler_go" ) -type ConfigServer struct { +type ConfigServerImpl struct { + Crawlers map[string]crawler.Crawler } -func (s *ConfigServer) Add(c context.Context, in *pb.Input) (*pb.Output, error) { +func (s *ConfigServerImpl) Add(c context.Context, in *pb.Input) (*pb.Output, error) { output := &pb.Output{} - if c, ok := g_crawlers[in.Name.String()]; ok { + if c, ok := s.Crawlers[in.Name.String()]; ok { rd, err := c.Add(in.Id) if err != nil { // process error @@ -21,9 +23,9 @@ func (s *ConfigServer) Add(c context.Context, in *pb.Input) (*pb.Output, error) } return output, nil } -func (s *ConfigServer) Remove(c context.Context, in *pb.Input) (*pb.Output, error) { +func (s *ConfigServerImpl) Remove(c context.Context, in *pb.Input) (*pb.Output, error) { output := &pb.Output{} - if c, ok := g_crawlers[in.Name.String()]; ok { + if c, ok := s.Crawlers[in.Name.String()]; ok { rd, err := c.Remove(in.Id) if err != nil { // process error @@ -34,11 +36,11 @@ func (s *ConfigServer) Remove(c context.Context, in *pb.Input) (*pb.Output, erro } return output, nil } -func (s *ConfigServer) Init(c context.Context, inputArray *pb.InputArray) (*pb.Output, error) { +func (s *ConfigServerImpl) Init(c context.Context, inputArray *pb.InputArray) (*pb.Output, error) { output := &pb.Output{} for _,in := range inputArray.In { - if c, ok := g_crawlers[in.Name.String()]; ok { + if c, ok := s.Crawlers[in.Name.String()]; ok { rd, err := c.Init(in.Path) if err != nil { // process error diff --git a/server_data.go b/impl/server_data.go similarity index 53% rename from server_data.go rename to impl/server_data.go index cabe023..1b8a6a6 100644 --- a/server_data.go +++ b/impl/server_data.go @@ -1,18 +1,20 @@ -package main +package impl import ( "golang.org/x/net/context" pb "loafle.com/overflow/crawler_go/grpc" + "loafle.com/overflow/crawler_go" ) -type DataServer struct { +type DataServerImpl struct { + Crawlers map[string]crawler.Crawler } -func (s *DataServer) Get(c context.Context, in *pb.Input) (*pb.Output, error) { +func (s *DataServerImpl) Get(c context.Context, in *pb.Input) (*pb.Output, error) { output := &pb.Output{} - if c, ok := g_crawlers[in.Name.String()]; ok { + if c, ok := s.Crawlers[in.Name.String()]; ok { rd, err := c.Get(in.Id) if err != nil { // process error diff --git a/server_status.go b/impl/server_status.go similarity index 53% rename from server_status.go rename to impl/server_status.go index 65c2b9e..dbe2ae0 100644 --- a/server_status.go +++ b/impl/server_status.go @@ -1,14 +1,14 @@ -package main +package impl import( "golang.org/x/net/context" pb "loafle.com/overflow/crawler_go/grpc" ) -type StatusServer struct { +type StatusServerImpl struct { } -func (s *StatusServer) Status(c context.Context, in *pb.Empty) (*pb.Boolean, error) { +func (s *StatusServerImpl) Status(c context.Context, in *pb.Empty) (*pb.Boolean, error) { output := &pb.Boolean{} output.Check =true return output, nil diff --git a/network_crawler.go b/network_crawler.go index cabe3ea..5fff75c 100644 --- a/network_crawler.go +++ b/network_crawler.go @@ -6,6 +6,7 @@ import ( "loafle.com/overflow/crawler_go" pb "loafle.com/overflow/crawler_go/grpc" "loafle.com/overflow/crawler_go/health_crawler/redis_protocol_crawler_go" + "loafle.com/overflow/rpc_network_crawler_go/impl" "log" "net" "loafle.com/overflow/crawler_go/health_crawler/activedirectory_protocol_crawler_go" @@ -94,5 +95,9 @@ func start(rc pb.ConfigServer, rd pb.DataServer, rs pb.StatusServer) { func main() { initCrawlers() - start(&ConfigServer{}, &DataServer{}, &StatusServer{}) + start(&impl.ConfigServerImpl{ + Crawlers : g_crawlers, + }, &impl.DataServerImpl{ + Crawlers : g_crawlers, + }, &impl.StatusServerImpl{}) } diff --git a/network_crawler_test.go b/network_crawler_test.go index bdec158..f06761b 100644 --- a/network_crawler_test.go +++ b/network_crawler_test.go @@ -19,7 +19,7 @@ type call func() crawler.Crawler func startRPCServerTest(cc call) { rr := cc() AddDelegate(pb.Crawlers_HEALTH_REDIS.String(), rr) - go start(&ConfigServer{}, &DataServer{},&StatusServer{}) + go start(&ConfigServerImpl{}, &DataServerImpl{},&StatusServerImpl{}) } func clientCall(t *testing.T, cl pb.Crawlers) {