背景
Buf 正在构建工具,使 Protobuf 可靠且易于服务所有者和客户使用,同时使其成为技术优势的明显选择。您的组织不应该重新发明轮子来高效地创建、维护和使用 Protobuf API。我们将为您处理 Protobuf 管理策略,以便您可以专注于重要的事情,使用 Buf 正在构建现代 Protobuf
官网地址:https://docs.buf.build/introduction
安装
buf
可以通过 bufbuild/homebrew-buf tap使用Homebrew为 Mac 或 Linux 安装。
brew tap bufbuild/buf
brew install buf
面临问题
Error: You are using macOS 10.13.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
解决方案
第一步
官方网址下载 Buf for Mac
第二步
说明:该文件是二进制可执行文件,重命名为buf,另外赋可执行权限
chmod 777 buf
第三步
将该buf文件移动到Path目录下
#查看go path目录
echo $PATH
#使用sudo 否则没有权限
sudo mv ~/Downloads/buf /usr/local/go/bin
第四步
创建目录&初始化配置
# 创建目录
$ mkdir demo-service && cd demo-service
# 创建buf.yaml
$ buf mod init && buf mod update
# 创建版本目录
$ mkdir -p demo/v1 && cd demo/v1
注意
buf 从1.0版本开始
使用buf config init
如继续使用 buf mod init 则提示如下:
buf mod init" has been moved to "buf config init