st-peter-client/scripts/gen-go.sh

34 lines
931 B
Bash
Executable File

#!/usr/bin/env bash
# Generate Go gRPC stubs from the vendored proto into go/genpb/auth.
# The proto's in-file `option go_package` targets the server's module; the
# M-flag mapping here overrides it for this client module.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$here/go"
export PATH="$(go env GOPATH)/bin:$PATH"
MOD=git.awesomike.com/pub/st-peter-client/go
# proto filename (relative to ../proto) -> Go package dir under the module
protos=(
st-peter-auth.proto:genpb/auth
st-peter-admin.proto:genpb/admin
)
files=()
mflags=()
for entry in "${protos[@]}"; do
f="${entry%%:*}"; pkg="${entry##*:}"
files+=("$f")
mflags+=("--go_opt=M$f=$MOD/$pkg" "--go-grpc_opt=M$f=$MOD/$pkg")
done
rm -rf genpb
protoc -I ../proto \
--go_out=. --go_opt=module="$MOD" \
--go-grpc_out=. --go-grpc_opt=module="$MOD" \
"${mflags[@]}" \
"${files[@]}"
echo "Generated Go stubs under go/genpb/"