Sample Generator for Go API Clients
A generator for samples showing how to make API calls with clients generated by gapic-generator-go.
Prerequisites
- proto descriptors of an API
- sample configuration written in gapic config*
Note: We are in the process of moving sample configuration out of gapic config into a separate sample config yaml file.
Refer to sample config spec for how to config a sample. Before that, samples can be configured using gapic config.
Installation
go get github.com/googleapis/gapic-generator-go/cmd/gen-go-sample
Or to install from source:
git pull https://github.com/googleapis/gapic-generator-go.git
cd gapic-generator-go
go install ./cmd/gen-go-sample
Invocation
gen-go-sample \
-clientpkg 'url/to/client/pkg;name' \
-gapic 'path/to/gapic/config/some_gapic.yaml' \
-o [OUTPUT_DIR] \
-desc 'path/to/proto/descriptor.desc'
Or to generate the descriptor files on the fly, run
gen-go-sample \
-clientpkg 'url/to/client/pkg;name' \
-gapic "path/to/gapic/config/some_gapic.yaml" \
-o [OUTPUT_DIR] \
-desc <(protoc -o /dev/stdout --include_imports -I "$COMMON_PROTO" -I a.proto b.proto)
- The
$COMMON_PROTO
variable represents a path to the googleapis/api-common-protos directory to import the configuration annotations.
- The -o flag is necessary because we need to know where generated files will live.
For example, to generate samples for the language API, run
export GOOGLEAPIS=/tmp/googleapis
git clone git@github.com:googleapis/googleapis.git $GOOGLEAPIS
export COMMON_PROTO=/tmp/common-protos
git clone git@github.com:googleapis/api-common-protos.git $COMMON_PROTOS
gen-go-sample \
-clientpkg 'cloud.google.com/go/language/apiv1;language' \
-gapic "$GOOGLEAPIS/google/cloud/language/v1/language_gapic.yaml" \
-o /tmp/language/samples/v1
-desc <(protoc -o /dev/stdout --include_imports -I "$COMMON_PROTO" "$GOOGLEAPIS"/google/cloud/language/v1/*.proto)