1 Star 0 Fork 0

小鱼儿小董子/dongli-platform

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
buddy.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
小鱼儿小董子 提交于 2025-01-15 13:53 +08:00 . 1111
package client
import (
"context"
"fmt"
"gitee.com/wanjimao/dongli-kit/logging/slogger"
"gitee.com/wanjimao/dongli-kit/server/pkg/sfx"
"github.com/abiosoft/ishell"
mm "github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata"
"google.golang.org/grpc/metadata"
buddy "gitee.com/wanjimao/dongli-platform/api/gen/buddy/api"
"gitee.com/wanjimao/dongli-platform/services/buddy/pkg/bfx"
)
// BuddyClient is the client for buddy service
type BuddyClient struct {
client buddy.BuddyServiceClient
cmd *ishell.Cmd
}
func CreateBuddyClient(host string) (*ishell.Cmd, error) {
client, err := bfx.NewBuddyClient(host, sfx.SecuritySettingsParams{})
if err != nil {
return nil, err
}
p := &BuddyClient{
client: client,
}
p.initShells()
return p.cmd, nil
}
func (p *BuddyClient) initShells() {
p.cmd = &ishell.Cmd{
Name: "buddy",
Help: "buddy service interactive",
Aliases: []string{"B"},
}
p.initSubShells()
}
func (p *BuddyClient) initSubShells() {
p.cmd.AddCmd(&ishell.Cmd{
Name: "add",
Help: "add buddy",
Aliases: []string{"A"},
Func: p.add,
})
}
func (p *BuddyClient) add(c *ishell.Context) {
c.ShowPrompt(false)
defer c.ShowPrompt(true)
msg := slogger.ReadLine(c, "buddy uid: ")
req := &buddy.AddBuddyRequest{
Uid: []string{msg},
ReqInfo: "test",
}
md := metadata.Pairs("authorization", fmt.Sprintf("%s %v", "bearer", "test"))
ctx := mm.MD(md).ToOutgoing(context.Background())
if response, err := p.client.AddBuddy(ctx, req); err != nil {
slogger.Warn(c, err)
} else {
slogger.Infof(c, "Response: %s", response)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanjimao/dongli-platform.git
git@gitee.com:wanjimao/dongli-platform.git
wanjimao
dongli-platform
dongli-platform
v0.0.59

搜索帮助