rpc_network_crawler_go/server_config.go
jackdaw@loafle.com e1747396da of_rpc => grpc
2017-04-14 18:40:04 +09:00

53 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
}