...

Package fieldbehavior

import "go.einride.tech/aip/fieldbehavior"
Overview
Index

Overview ▾

Package fieldbehavior provides primitives for implementing AIP fieldbehavior annotations.

See: https://google.aip.dev/203 (Field behavior documentation)

func ClearFields

func ClearFields(message proto.Message, behaviorsToClear ...annotations.FieldBehavior)

ClearFields clears all fields annotated with any of the provided behaviors. This can be used to ignore fields provided as input that have field_behavior's such as OUTPUT_ONLY and IMMUTABLE.

See: https://google.aip.dev/161#output-only-fields

func CopyFields

func CopyFields(dst, src proto.Message, behaviorsToCopy ...annotations.FieldBehavior)

CopyFields copies all fields annotated with any of the provided behaviors from src to dst.

func Get

func Get(field protoreflect.FieldDescriptor) []annotations.FieldBehavior

Get returns the field behavior of the provided field descriptor.

func Has

func Has(field protoreflect.FieldDescriptor, want annotations.FieldBehavior) bool

Has returns true if the provided field descriptor has the wanted field behavior.

func ValidateImmutableFieldsWithMask

func ValidateImmutableFieldsWithMask(m proto.Message, mask *fieldmaskpb.FieldMask) error

ValidateImmutableFieldsWithMask returns a validation error if the message or field mask contains a field that is immutable and a change to an immutable field is requested. This can be used when validating update requests and want to return INVALID_ARGUMENT to the user. If you want to ignore immutable fields rather than error then use ClearFields().

See: https://aip.dev/203

func ValidateRequiredFields

func ValidateRequiredFields(m proto.Message) error

ValidateRequiredFields returns a validation error if any field annotated as required does not have a value. See: https://aip.dev/203

func ValidateRequiredFieldsWithMask

func ValidateRequiredFieldsWithMask(m proto.Message, mask *fieldmaskpb.FieldMask) error