rpc_network_crawler_go/config_server.go
jackdaw@loafle.com 484c661739 of_rpc => grpc
2017-04-13 16:43:33 +09:00

54 lines
1.1 KiB
Go

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) {
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
}
func (s *ConfigServer) Remove(c context.Context, in *pb.Input) (*pb.Output, error) {
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
}
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
}