Documentation ¶
Index ¶
- func Error(ctx context.Context, field string, msg string) error
- func Errorf(ctx context.Context, field string, msg string, items ...interface{}) error
- type Validation
- func (valid *Validation) Error(msg string, items ...interface{}) *ValidationError
- func (valid *Validation) Expect(cond bool, msg string, items ...interface{}) *ValidationError
- func (valid *Validation) NullableString(name string, fn func(s *string))
- func (valid *Validation) Ok() bool
- func (valid *Validation) Optional(name string, fn func(i interface{}))
- func (valid *Validation) OptionalBool(name string, fn func(b bool))
- func (valid *Validation) OptionalString(name string, fn func(s string))
- func (valid *Validation) WithInput(input map[string]interface{}) *Validation
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Validation ¶
type Validation struct {
// contains filtered or unexported fields
}
func (*Validation) Error ¶
func (valid *Validation) Error(msg string, items ...interface{}) *ValidationError
Creates a validation error unconditionally.
func (*Validation) Expect ¶
func (valid *Validation) Expect(cond bool, msg string, items ...interface{}) *ValidationError
Asserts that a condition is true, recording a GraphQL error with the given message if not.
func (*Validation) NullableString ¶
func (valid *Validation) NullableString(name string, fn func(s *string))
Fetches a nullable string from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but null, the function is called with null set to true. Otherwise, the function is called with the string for the user to conduct further validation with.
func (*Validation) Optional ¶
func (valid *Validation) Optional(name string, fn func(i interface{}))
Fetches an item from the validation context, which must have an input registered. If the field is not present, the callback is not run. Otherwise, the function is called with the value for the user to conduct further validation with.
func (*Validation) OptionalBool ¶
func (valid *Validation) OptionalBool(name string, fn func(b bool))
Fetches a boolean from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but not a boolean, an error is recorded. Otherwise, the function is called with the boolean for the user to conduct further validation with.
func (*Validation) OptionalString ¶
func (valid *Validation) OptionalString(name string, fn func(s string))
Fetches a string from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but not a string, an error is recorded. Otherwise, the function is called with the string for the user to conduct further validation with.
func (*Validation) WithInput ¶
func (valid *Validation) WithInput(input map[string]interface{}) *Validation
Adds an input map to a validation context.
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
func (*ValidationError) And ¶
func (err *ValidationError) And(cond bool, msg string, items ...interface{}) *ValidationError
Composes another assertion onto the same validation context which initially created an error. Short-circuiting is used, such that if the earlier condition failed, the new condition is not considered.
func (*ValidationError) WithField ¶
func (err *ValidationError) WithField(field string) *ValidationError
Associates a field name with an error.