Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add XGoogFieldMaskHeader constant #321

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions v2/callctx/callctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ import (
)

const (
// XGoogFieldMask is the canonical header key for the [System Parameter]
// that specifies the response read mask. The value(s) for this header
// must adhere to format described in [fieldmaskpb].
//
// [System Parameter]: https://cloud.google.com/apis/docs/system-parameters
// [fieldmaskpb]: https://google.golang.org/protobuf/types/known/fieldmaskpb
XGoogFieldMask = "x-goog-fieldmask"
noahdietz marked this conversation as resolved.
Show resolved Hide resolved

headerKey = contextKey("header")
)

Expand Down
22 changes: 22 additions & 0 deletions v2/callctx/callctx_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"fmt"

"github.com/googleapis/gax-go/v2/callctx"
"google.golang.org/genproto/googleapis/api/metric"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)

func ExampleSetHeaders() {
Expand All @@ -47,3 +49,23 @@ func ExampleSetHeaders() {
fmt.Println(headers["key"][0])
// Output: value
}

func ExampleXGoogFieldMask() {
ctx := context.Background()
ctx = callctx.SetHeaders(ctx, callctx.XGoogFieldMask, "field_one,field.two")

// Send the returned context to the request you are making.
}

func ExampleXGoogFieldMask_fieldmaskpb() {
// Build a mask using the expected response protobuf message.
mask, err := fieldmaskpb.New(&metric.MetricDescriptor{}, "display_name", "metadata.launch_stage")
if err != nil {
// handle error
}

ctx := context.Background()
ctx = callctx.SetHeaders(ctx, callctx.XGoogFieldMask, mask.String())

// Send the returned context to the request you are making.
}
11 changes: 8 additions & 3 deletions v2/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func goVersion() string {
return "UNKNOWN"
}

// XGoogHeader is for use by the Google Cloud Libraries only.
// XGoogHeader is for use by the Google Cloud Libraries only. See package
// [github.com/googleapis/gax-go/v2/callctx] for help setting/retrieving
// request/response headers.
//
// XGoogHeader formats key-value pairs.
// The resulting string is suitable for x-goog-api-client header.
Expand All @@ -125,7 +127,8 @@ func XGoogHeader(keyval ...string) string {
}

// InsertMetadataIntoOutgoingContext is for use by the Google Cloud Libraries
// only.
// only. See package [github.com/googleapis/gax-go/v2/callctx] for help
// setting/retrieving request/response headers.
//
// InsertMetadataIntoOutgoingContext returns a new context that merges the
// provided keyvals metadata pairs with any existing metadata/headers in the
Expand All @@ -137,7 +140,9 @@ func InsertMetadataIntoOutgoingContext(ctx context.Context, keyvals ...string) c
return metadata.NewOutgoingContext(ctx, insertMetadata(ctx, keyvals...))
}

// BuildHeaders is for use by the Google Cloud Libraries only.
// BuildHeaders is for use by the Google Cloud Libraries only. See package
// [github.com/googleapis/gax-go/v2/callctx] for help setting/retrieving
// request/response headers.
//
// BuildHeaders returns a new http.Header that merges the provided
// keyvals header pairs with any existing metadata/headers in the provided
Expand Down