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

feat(functions/metadata): Special-case marshaling #2669

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions functions/metadata/metadata.go
Expand Up @@ -77,6 +77,23 @@ func (r *Resource) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON specializes the Resource marshalling to handle the case where the
// value is a string instead of a map. See the comment above on RawPath for why this
// needs to be handled.
func (r *Resource) MarshalJSON() ([]byte, error) {
roffjulie marked this conversation as resolved.
Show resolved Hide resolved
// If RawPath is set, use that as the value.
if r.RawPath != "" {
return []byte(fmt.Sprintf("%q", r.RawPath)), nil
}

// Otherwise, accept whatever the result of the normal marshal would be.
b, err := json.Marshal(r)
if err != nil {
return nil, err
}
return b, nil
}

type contextKey string

// GCFContextKey satisfies an interface to be able to use contextKey to read
Expand Down