Files
chain33-dtalk/service/backup/api/client.go
2022-03-17 15:59:24 +08:00

42 lines
910 B
Go

package backup
import (
"context"
"fmt"
"gitlab.33.cn/chat/dtalk/pkg/naming"
"gitlab.33.cn/chat/dtalk/pkg/net/grpc"
"google.golang.org/grpc/resolver"
"time"
)
// AppID unique app id for service discovery
//const AppID = "identify.service.pusher"
type Client struct {
client BackupClient
}
func New(etcdAddr, schema, srvName string, dial time.Duration) *Client {
rb := naming.NewResolver(etcdAddr, schema)
resolver.Register(rb)
addr := fmt.Sprintf("%s:///%s", schema, srvName) // "schema://[authority]/service"
fmt.Println("backup rpc client call addr:", addr)
conn, err := grpc.NewGRPCConn(addr, dial)
if err != nil {
panic(err)
}
return &Client{
client: NewBackupClient(conn),
}
}
func (c *Client) Retrieve(ctx context.Context, tp QueryType, val string) (*RetrieveReply, error) {
reply, err := c.client.Retrieve(ctx, &RetrieveReq{
Type: tp,
Val: val,
})
return reply, err
}