rpc_network_crawler_go/config_server.go

53 lines
1.1 KiB
Go
Raw Normal View History

2017-04-13 07:12:21 +00:00
package main
import (
"golang.org/x/net/context"
pb "loafle.com/overflow/crawler_go/grpc"
)
type ConfigServer struct {
}
func (s *ConfigServer) Add(c context.Context, in *pb.Input) (*pb.Output, error) {
2017-04-13 07:43:33 +00:00
output := &pb.Output{}
if c, ok := g_crawlers[in.Name.String()]; ok {
rd, err := c.Add(in.Id)
if err != nil {
// process error
}
output.Data = rd
} else {
output.Data = []byte("Not Assign Crawler")
}
return output, nil
2017-04-13 07:12:21 +00:00
}
func (s *ConfigServer) Remove(c context.Context, in *pb.Input) (*pb.Output, error) {
2017-04-13 07:43:33 +00:00
output := &pb.Output{}
if c, ok := g_crawlers[in.Name.String()]; ok {
rd, err := c.Remove(in.Id)
if err != nil {
// process error
}
output.Data = rd
} else {
output.Data = []byte("Not Assign Crawler")
}
return output, nil
2017-04-13 07:12:21 +00:00
}
2017-04-13 07:43:33 +00:00
func (s *ConfigServer) 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 {
rd, err := c.Init(in.Path)
if err != nil {
// process error
}
output.Data = rd
} else {
output.Data = []byte("Not Assign Crawler")
}
}
return output, nil
2017-04-13 07:12:21 +00:00
}