138 lines
2.5 KiB
Go
138 lines
2.5 KiB
Go
package crawler_manager
|
|
|
|
import (
|
|
"path/filepath"
|
|
"google.golang.org/grpc"
|
|
"log"
|
|
g "loafle.com/overflow/crawler_go/grpc"
|
|
"context"
|
|
|
|
"encoding/json"
|
|
)
|
|
|
|
|
|
func CallAdd() {
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("did not connect: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
in := &g.Input{}
|
|
|
|
in.Id = "test_redis_sid"
|
|
in.Name = g.Crawlers_HEALTH_REDIS
|
|
|
|
out, err := cc.Add(context.Background(), in)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
log.Println(out)
|
|
|
|
}
|
|
|
|
func CallInit2(address string, cpm *map[string][]string) bool {
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("did not connect: %v", err)
|
|
return false
|
|
}
|
|
defer conn.Close()
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
in := &g.Init{}
|
|
|
|
in.Path = "/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/"
|
|
//in.Name = g.Crawlers(g.Crawlers_value[""])
|
|
in.Name = g.Crawlers_HEALTH_REDIS
|
|
|
|
inArr := &g.InputArray{}
|
|
inArr.In = append(inArr.In, in)
|
|
|
|
outInit, errInit := cc.Init(context.Background(), inArr)
|
|
if errInit != nil {
|
|
log.Println(errInit)
|
|
return false
|
|
}
|
|
log.Println(outInit)
|
|
|
|
return true
|
|
}
|
|
|
|
func CallInit(crawlerName string, path string) {
|
|
|
|
port := portMap[crawlerName]
|
|
|
|
conn, err := grpc.Dial(address+port, grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("did not connect: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
in := &g.Init{}
|
|
|
|
in.Path = filepath.Dir(path)+ "/"
|
|
|
|
in.Name = g.Crawlers(g.Crawlers_value[crawlerName])
|
|
|
|
inArr := &g.InputArray{}
|
|
inArr.In = append(inArr.In, in)
|
|
|
|
outInit, errInit := cc.Init(context.Background(), inArr)
|
|
if errInit != nil {
|
|
log.Println(errInit)
|
|
}
|
|
log.Println(outInit)
|
|
|
|
}
|
|
|
|
func CallRemove() {
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("did not connect: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
cc := g.NewConfigClient(conn)
|
|
|
|
inR := &g.Input{}
|
|
inR.Id = "123123"
|
|
inR.Name = g.Crawlers_HEALTH_DNS
|
|
|
|
outRem, errRem := cc.Remove(context.Background(), inR)
|
|
if errRem != nil {
|
|
log.Println(errRem)
|
|
}
|
|
log.Println(outRem)
|
|
|
|
}
|
|
|
|
func CallGet() {
|
|
conn, err := grpc.Dial("localhost:50000", grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("did not connect: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
c := g.NewDataClient(conn)
|
|
|
|
in := &g.Input{
|
|
Name: g.Crawlers_HEALTH_REDIS,
|
|
Id: "test_redis_sid",
|
|
}
|
|
|
|
out, err := c.Get(context.Background(), in)
|
|
if err != nil {
|
|
log.Fatalf("could not greet: %v", err)
|
|
}
|
|
|
|
var check bool
|
|
json.Unmarshal(out.Data, &check)
|
|
log.Println(check)
|
|
} |