spider-scheduler/rpc/rpc.go

32 lines
753 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rpc
import (
"github.com/furryboard/spider-scheduler/pkg/conf"
"github.com/furryboard/spider-scheduler/pkg/log"
"github.com/furryboard/spider-scheduler/rpc/pb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"strconv"
"sync"
)
var (
Conn *grpc.ClientConn
biliAPI pb.BiliAPIClient
once sync.Once
)
func SpiderCore() pb.BiliAPIClient {
once.Do(InitBiliAPI)
return biliAPI
}
func InitBiliAPI() {
addr := conf.Conf.SpiderCore.Host + ":" + strconv.Itoa(int(conf.Conf.SpiderCore.Port))
Conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Logger().Fatalf("连接到RPC服务器时发生错误%s", err)
}
biliAPI = pb.NewBiliAPIClient(Conn)
}