109 lines
1.9 KiB
Go
109 lines
1.9 KiB
Go
|
package crawler_manager
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
"google.golang.org/grpc"
|
||
|
"log"
|
||
|
g "loafle.com/overflow/crawler_go/grpc"
|
||
|
"context"
|
||
|
"loafle.com/overflow/crawler_go/config"
|
||
|
"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 CallInit(c *config.Config, path string) {
|
||
|
|
||
|
port := portMap[c.Crawler.Name]
|
||
|
|
||
|
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[c.Crawler.Name])
|
||
|
|
||
|
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)
|
||
|
}
|