- Notifications
You must be signed in to change notification settings - Fork0
dyrnq/cobra-example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
this project is a POC using cobra, viper, pflag.
go mod init github.com/dyrnq/cobra-examplecobra-cli init --vipercobra-cli add serve --vipercobra-cli add version --viperGOPROXY=https://goproxy.io,direct go mod tidy
make run
## test case./main serve./main serve --server.address 127.0.0.1SERVER_ADDRESS=0.0.0.0 ./main serveSERVER_ADDRESS=0.0.0.0 SERVER_PORT=7777 ./main serve --config ./config-demo.yamlSERVER_ADDRESS=0.0.0.0 ./main serve --server.address 127.0.0.1 --server.port=8899SERVER_ADDRESS=0.0.0.0 ./main serve --server.address 127.0.0.1 --server.port=35566 --config ./config-demo.yaml
Priority
--args> ENV> config.yaml
Addhttps://github.com/grpc/grpc-go/tree/master/examples/helloworld to subcomand
protoc \--go_out=. \--go_opt=paths=source_relative \--go-grpc_out=. \--go-grpc_opt=paths=source_relative \pkg/grpc/helloworld/*.proto
bash: protoc: command not found
# https://github.com/protocolbuffers/protobuf/releases/download/v28.0/protoc-28.0-linux-x86_64.zipPROTOC_VER=28.0if ["$(uname -m)"="x86_64" ];then arch="amd64";fiif ["$(uname -m)"="aarch64" ];then arch="arm64";fiPROTOC_ZIP="protoc-${PROTOC_VER}-linux-${arch}.zip"url="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/${PROTOC_ZIP}";url=${url/github.com/mirror.ghproxy.com/github.com}echo"${url}"curl -O -fL -# --retry 10${url}unzip -o$PROTOC_ZIP -d /usr/local bin/protocunzip -o$PROTOC_ZIP -d /usr/local'include/*'rm -f$PROTOC_ZIP
protoc-gen-go: program not found or is not executablePlease specify a program using absolute path or make sure the program is available in your PATH system variable--go_out: protoc-gen-go: Plugin failed with status code 1.
$ GOPROXY=https://goproxy.io,direct go install google.golang.org/protobuf/cmd/protoc-gen-go@latestgo: downloading google.golang.org/protobuf v1.34.2$ GOPROXY=https://goproxy.io,direct go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestgo: downloading google.golang.org/grpc v1.66.0go: downloading google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1go: downloading google.golang.org/protobuf v1.34.1
pkg/grpc/helloworld/helloworld_grpc.pb.go:33:16: undefined: grpc.SupportPackageIsVersion9
$ GOPROXY=https://goproxy.io,direct go get -u google.golang.org/grpc@latestgo: downloading golang.org/x/net v0.26.0go: downloading golang.org/x/sys v0.21.0go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117go: downloading golang.org/x/net v0.29.0go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1go: downloading google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1go: downloading golang.org/x/text v0.16.0go: downloading golang.org/x/text v0.18.0go: upgraded golang.org/x/net v0.23.0 => v0.29.0go: upgraded golang.org/x/sys v0.18.0 => v0.25.0go: upgraded golang.org/x/text v0.14.0 => v0.18.0go: upgraded google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c => v0.0.0-20240903143218-8af14fe29dc1go: upgraded google.golang.org/grpc v1.62.1 => v1.66.0go: upgraded google.golang.org/protobuf v1.33.0 => v1.34.2
cobra-cli add grpc-helloworld --parent rootCmd --vipercobra-cli add server --parent grpcHelloworldCmd --vipercobra-cli add client --parent grpcHelloworldCmd --viper
./main grpc-helloworld server --grpc.address 0.0.0.0 --grpc.port 50051./main grpc-helloworld client --grpc.server 127.0.0.1:50051 --msg 你好
cobra-cli add grpc-stream --parent rootCmd --vipercobra-cli add grpc-stream-server --parent grpcStreamCmd --vipercobra-cli add grpc-stream-client --parent grpcStreamCmd --viper./main grpc-stream server./main grpc-stream client
About
cobra-example
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.