fieldmask

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 13 Imported by: 0

README

Fieldmask

License GoDev Reference Go Report Card

Package fieldmask provides protobuf field masking for projections and updates.

It follows Google API Improvement Proposal guidelines by default, but provides options that allow it to fall back to the behavior of basic FieldMask documentation.

Documentation

Overview

Package fieldmask provides protobuf field masking for projections and updates.

It follows Google API Improvement Proposal guidelines by default, but provides options that allow it to fall back to the behavior of basic FieldMask documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldMask

type FieldMask[T proto.Message] struct {
	// contains filtered or unexported fields
}

func FromProto

func FromProto[T proto.Message](fieldMask *fieldmaskpb.FieldMask, options ...Option) (*FieldMask[T], error)

func New

func New[T proto.Message](paths []string, options ...Option) (*FieldMask[T], error)

func Parse

func Parse[T proto.Message](paths string, options ...Option) (*FieldMask[T], error)

func (*FieldMask[T]) Append

func (fm *FieldMask[T]) Append(path string) error

func (*FieldMask[T]) Clone

func (fm *FieldMask[T]) Clone(msg T) T

func (*FieldMask[T]) Mask

func (fm *FieldMask[T]) Mask(msg T)

func (*FieldMask[T]) Paths

func (fm *FieldMask[T]) Paths() []string

func (*FieldMask[T]) Proto

func (fm *FieldMask[T]) Proto() *fieldmaskpb.FieldMask

func (*FieldMask[T]) String

func (fm *FieldMask[T]) String() string

func (*FieldMask[T]) Update

func (fm *FieldMask[T]) Update(dst, src T) error

type FieldName

type FieldName int

FieldName specifies which field name to prefer when parsing and outputting paths.

const (
	// TextFieldName uses the text field name, which is typically lower_snake_case.
	// This is the default behavior.
	TextFieldName FieldName = iota
	// JSONFieldName uses the JSON field name, which is typically lowerCamelCase.
	JSONFieldName
)

type MaskUnknowns

type MaskUnknowns int

MaskUnknowns specifies how to handle unknown fields when a message is masked.

const (
	// MaskRemovesUnknowns removes any unknown fields when a message is masked.
	// This is the default behavior.
	MaskRemovesUnknowns MaskUnknowns = iota
	// MaskRetainsUnknowns retains any unknown fields when a message is masked.
	MaskRetainsUnknowns
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithExtensions

func WithExtensions(allow bool) Option

WithExtensions returns an option that sets whether extensions are allowed.

func WithFieldName

func WithFieldName(mode FieldName, strict bool) Option

WithFieldName returns an option that sets the given mode for field names. If strict is false, either name will be accepted when parsing paths. The specified mode is always used when outputing paths.

func WithMaskUnknowns

func WithMaskUnknowns(mode MaskUnknowns) Option

WithMaskUnknowns returns an option that sets the given mode for masking unknown fields.

func WithMessageDescriptor

func WithMessageDescriptor(desc protoreflect.MessageDescriptor) Option

WithMessageDescriptor returns an option that sets the message descriptor. This is useful for dynamic types constructed at runtime.

func WithUpdateRepeated

func WithUpdateRepeated(mode UpdateRepeated) Option

WithUpdateRepeated returns an option that sets the given mode for updating repeated fields.

func WithUpdateUnknowns

func WithUpdateUnknowns(mode UpdateUnknowns) Option

WithUpdateUnknowns returns an option that sets the given mode for updating unknown fields.

type UpdateRepeated

type UpdateRepeated int

UpdateRepeated specifies how to update repeated fields.

const (
	// UpdateReplacesRepeated replaces any repeated fields on an update.
	// This is the default behavior.
	UpdateReplacesRepeated UpdateRepeated = iota
	// UpdateAppendsRepeated appends any repeated fields on an update.
	UpdateAppendsRepeated
)

type UpdateUnknowns

type UpdateUnknowns int

UpdateUnknowns specifies how to update unknown fields.

const (
	// UpdateRetainsUnknowns retains any unknown fields on the destination message
	// when it's updated. This is the default behavior.
	UpdateRetainsUnknowns UpdateUnknowns = iota
	// UpdateAppendsUnknowns appends any unknown fields from the source message
	// to any unknown fields on the destination message when it's updated.
	UpdateAppendsUnknowns
	// UpdateReplacesUnknowns replaces any unknown fields on the destination message
	// with any unknown fields from the source message when it's updated.
	UpdateReplacesUnknowns
)

Directories

Path Synopsis
internal
quote
Package quote is forked from strconv in the go standard library.
Package quote is forked from strconv in the go standard library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL