百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

protoc-gen-cobra

> 编程语言
开源

用于 gRPC 客户端的 Cobra 命令行工具生成器

184 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 gRPC 客户端的 Cobra 命令行工具生成器

⛔ DEPRECATED

This repository is no longer actively maintained. All future work has moved here.

protoc-gen-cobra

Cobra command line tool generator for Go gRPC.

What's this?

A plugin for the protobuf compiler protoc, that generates Go code using cobra. It is capable of generating client code for command line tools consistent with your protobuf description.

This:

service Bank {
	rpc Deposit(DepositRequest) returns (DepositReply)
}

message DepositRequest {
	string account = 1;
	double amount = 2;
}

message DepositReply {
	string account = 1;
	double balance = 2;
}

produces a client that can do:

echo '{"account":"foobar","amount":10}' | command bank deposit

It generates one cobra.Command per gRPC service (e.g. bank). The service's rpc methods are sub-commands, and share the same command line semantics. They take a request file for input, or stdin, and prints the response to the terminal, in the specified format. The client currently supports basic connectivity settings such as tls on/off, tls client authentication and so on.

…

This is an experiment. Was bored of writing the same boilerplate code to interact with gRPC servers, wanted something like kubectl. At some point I might want to generate server code too, similar to what go-swagger does. Perhaps look at using go-openapi too. Tests are lacking.

Streams

gRPC client and server streams are supported, you can do pipes from the command line. On server streams, each response is printed out using the specified response format. Client streams input must be formatted as json, one document per line, from a file or stdin.

Example client stream:

$ cat req.json
{"key":"hello","value":"world"}
{"key":"foo","value":"bar"}

$ ./example cache multiset -f req.json

Example client and server streams:

$ echo -ne '{"key":"hello"}\n{"key":"foo"}\n' | ./example cache multiget
{"value":"world"}
{"value":"bar"}

Idle server streams hang until the server closes the stream, or a timeout occurs.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言