Documentation
¶
Index ¶
- Variables
- func MakeProgram(env *cel.Env, expression string, container string) (cel.Program, error)
- type Check
- type CheckError
- func (*CheckError) Descriptor() ([]byte, []int)deprecated
- func (x *CheckError) GetFail() string
- func (x *CheckError) GetId() string
- func (x *CheckError) GetPath() string
- func (*CheckError) ProtoMessage()
- func (x *CheckError) ProtoReflect() protoreflect.Message
- func (x *CheckError) Reset()
- func (x *CheckError) String() string
- func (c *CheckError) WithParentField(parent string, key any) *CheckError
- func (c *CheckError) WithPath(path string) *CheckError
- type Checker
- type MessageValidator
- type ValidationError
- type ValidationOption
- type Validator
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 {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // optional id of the check that failed
Fail string `protobuf:"bytes,2,opt,name=fail,proto3" json:"fail,omitempty"` // optional message to display
Path string `protobuf:"bytes,3,opt,name=path,proto3" json:"path,omitempty"` // path to the field name that failed, if empty then it was a message check
// contains filtered or unexported fields
}
func (*CheckError) Descriptor
deprecated
added in
v0.6.0
func (*CheckError) Descriptor() ([]byte, []int)
Deprecated: Use CheckError.ProtoReflect.Descriptor instead.
func (*CheckError) GetFail ¶ added in v0.6.0
func (x *CheckError) GetFail() string
func (*CheckError) GetId ¶ added in v0.6.0
func (x *CheckError) GetId() string
func (*CheckError) GetPath ¶ added in v0.6.0
func (x *CheckError) GetPath() string
func (*CheckError) ProtoMessage ¶ added in v0.6.0
func (*CheckError) ProtoMessage()
func (*CheckError) ProtoReflect ¶ added in v0.6.0
func (x *CheckError) ProtoReflect() protoreflect.Message
func (*CheckError) Reset ¶ added in v0.6.0
func (x *CheckError) Reset()
func (*CheckError) String ¶ added in v0.6.0
func (x *CheckError) String() string
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, options ...ValidationOption) (result ValidationError)
Validate runs all message and field checkers with the message. Always returns a ValidationError (error) which can be empty (no failed checks) With options you can control what to validations to skip.
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).
type ValidationOption ¶ added in v0.5.0
type ValidationOption byte
const FieldsSetOnly ValidationOption = 1
Only if a field is set (non-zero value for proto3) then validate its content.
type Validator ¶
type Validator interface {
Validate(options ...ValidationOption) ValidationError
}
Validator is an interface that can be implemented by a message to validate itself.