12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package middleground
- import (
- "context"
- "log"
- "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
- "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
- "github.com/zeromicro/go-zero/core/discov"
- "github.com/zeromicro/go-zero/zrpc"
- )
- type resourceCenter struct {
- hosts []string
- key string
- }
- func newResourceCenter(hosts []string, key string) *resourceCenter {
- return &resourceCenter{
- hosts: hosts,
- key: key,
- }
- }
- func (r *resourceCenter) newClient() zrpc.Client {
- client, err := zrpc.NewClient(zrpc.RpcClientConf{
- Etcd: discov.EtcdConf{
- Hosts: r.hosts,
- Key: r.key,
- },
- })
- if err != nil {
- log.Println(err)
- return nil
- }
- return client
- }
- //
- func (r *resourceCenter) Haspowers(accountId, entAccountId, entId, entUserId int64) *pb.HaspowersResp {
- client := r.newClient()
- if client == nil {
- return nil
- }
- defer client.Conn().Close()
- resp, err := resource.NewResource(client).Haspowers(context.Background(), &pb.HaspowersReq{
- Appid: "10000",
- AccountId: accountId,
- EntAccountId: entAccountId,
- EntId: entId,
- EntUserId: entUserId,
- })
- if err != nil {
- log.Println(err)
- return nil
- }
- return resp
- }
|