Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
// repeated check.Check field = 20030916;
E_Field = &file_check_proto_extTypes[1]
)
Extension fields to descriptorpb.FieldOptions.
var (
// repeated check.Check message = 20030916;
E_Message = &file_check_proto_extTypes[0]
)
Extension fields to descriptorpb.MessageOptions.
var File_check_proto protoreflect.FileDescriptor
Functions ¶
Types ¶
type Check ¶
type Check struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // optional identifier for lookup purposes Fail string `protobuf:"bytes,2,opt,name=fail,proto3" json:"fail,omitempty"` // optional message to report when the check fails Cel string `protobuf:"bytes,3,opt,name=cel,proto3" json:"cel,omitempty"` // Google/CEL expression (https://github.com/google/cel-spec) // contains filtered or unexported fields }
func (*Check) Descriptor
deprecated
func (*Check) ProtoMessage ¶
func (*Check) ProtoMessage()
func (*Check) ProtoReflect ¶
func (x *Check) ProtoReflect() protoreflect.Message
type CheckError ¶
type CheckError struct { Path string // path to the field that failed, if empty then the field is part of the root message Id string // optional id of the check that failed Fail string // optional message to display Err error // set if the check failed due to an error }
CheckError captures a failed check.
func (CheckError) WithParentField ¶
func (c CheckError) WithParentField(parent string, key any) CheckError
WithParentField returns a new CheckError with the parent field prepended to the path.
func (CheckError) WithPath ¶
func (c CheckError) WithPath(path string) CheckError
WithPath returns a new CheckError with the path set.
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker performs one check using a CEL program.
func NewChecker ¶
func NewChecker(id string, fail string, cel string, fieldName string, isOptional bool, program cel.Program) Checker
NewChecker creates a Checker
func (Checker) WithEnabledFunc ¶
type MessageValidator ¶
type MessageValidator struct {
// contains filtered or unexported fields
}
MessageValidator holds a collection of checkers to validate a message.
func NewMessageValidator ¶
func NewMessageValidator(messageCheckers, fieldCheckers []Checker) MessageValidator
NewMessageValidator creates a MessageValidator using two collections of checkers
func (MessageValidator) Validate ¶
func (m MessageValidator) Validate(this any) (result ValidationError)
Validate runs all message and field checkers with the message. Always returns a ValidationError which can be empty (no failed checks)
type ValidationError ¶
type ValidationError []CheckError
ValidationError is a collection of CheckError.
func AsValidationError ¶ added in v0.3.0
func AsValidationError(err error) ValidationError
AsValidationError converts an error or nil to a valid ValidationError (so could be empty).