53 lines
1.1 KiB
Go
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
|
|
}
|