gkgen

package
v0.0.0-...-25e1d4e Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BCP47Validator

type BCP47Validator struct {
	// contains filtered or unexported fields
}

BCP47Validator generates code that will verify if a field is a BCP47 compatible string https://tools.ietf.org/html/bcp47

func NewBCP47Validator

func NewBCP47Validator() *BCP47Validator

NewBCP47Validator holds the BCP47Validator state

func (*BCP47Validator) Generate

func (s *BCP47Validator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*BCP47Validator) Name

func (s *BCP47Validator) Name() string

Name provides access to the name field

type Generater

type Generater interface {
	Generate(reflect.Type, reflect.StructField, []string) (string, error)
	Name() string
}

Generater defines the behavior of types that generate validation code

type HexValidator

type HexValidator struct {
	// contains filtered or unexported fields
}

HexValidator generates code that will verify if a field is a hex string 0x prefix is optional

func NewHexValidator

func NewHexValidator() *HexValidator

NewHexValidator holds the HexValidator state

func (*HexValidator) Generate

func (s *HexValidator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*HexValidator) Name

func (s *HexValidator) Name() string

Name provides access to the name field

type LengthValidateGen

type LengthValidateGen struct {
	// contains filtered or unexported fields
}

LengthValidateGen generates code that will verify the exact length of a String or String Pointer field. Slice and Array support coming later. It will flag nil string pointers as valid, use in conjunction with NotNil validator if you don't want nil values

func NewLengthValidator

func NewLengthValidator() *LengthValidateGen

NewLengthValidator holds LengthValidator state

func (*LengthValidateGen) Generate

func (s *LengthValidateGen) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*LengthValidateGen) Name

func (s *LengthValidateGen) Name() string

Name provides access to the name field

type MinLengthValidateGen

type MinLengthValidateGen struct {
	// contains filtered or unexported fields
}

MinLengthValidateGen generates code that will verify the MinLength of a String or String pointer. It will flag nil pointers as valid, use in conjunction with NotNil validator if you don't want nil values

func NewMinLengthValidator

func NewMinLengthValidator() *MinLengthValidateGen

NewMinLengthValidator holds MinLengthValidator state

func (*MinLengthValidateGen) Generate

func (s *MinLengthValidateGen) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*MinLengthValidateGen) Name

func (s *MinLengthValidateGen) Name() string

Name provides access to the name field

type NotEqualValidator

type NotEqualValidator struct {
	// contains filtered or unexported fields
}

NotEqualValidator generates code that will verify a fields does not equal a set value The validator will look at the field or the dereferenced value of the field nil values for a field are not considered invalid

func NewNotEqualValidator

func NewNotEqualValidator() *NotEqualValidator

NewNotEqualValidator holds the NotEqualValidator state

func (*NotEqualValidator) Generate

func (s *NotEqualValidator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*NotEqualValidator) Name

func (s *NotEqualValidator) Name() string

Name provides access to the name field

type NotNilValidator

type NotNilValidator struct {
	// contains filtered or unexported fields
}

NotNilValidator generates code that will verify if a pointer is nil Slice and Array support coming later. It will flag nil string pointers as valid, use in conjunction with NotNil validator if you don't want nil values

func NewNotNilValidator

func NewNotNilValidator() *NotNilValidator

NewNotNilValidator holds the NotNilValidator state

func (*NotNilValidator) Generate

func (s *NotNilValidator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*NotNilValidator) Name

func (s *NotNilValidator) Name() string

Name provides access to the name field

type SetValidator

type SetValidator struct {
	// contains filtered or unexported fields
}

SetValidator generates code that will verify a fields does Set one of an allowed set of values The SetValidator will look at the field or the dereferenced value of the field nil values for a field are not considered invalid

func NewSetValidator

func NewSetValidator() *SetValidator

NewSetValidator holds the SetValidator state

func (*SetValidator) Generate

func (s *SetValidator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*SetValidator) Name

func (s *SetValidator) Name() string

Name provides access to the name field

type UUIDValidator

type UUIDValidator struct {
	// contains filtered or unexported fields
}

UUIDValidator generates code that will verify if a field is a UUID string

func NewUUIDValidator

func NewUUIDValidator() *UUIDValidator

NewUUIDValidator holds the UUIDValidator state

func (*UUIDValidator) Generate

func (s *UUIDValidator) Generate(sType reflect.Type, fieldStruct reflect.StructField, params []string) (string, error)

Generate generates validation code

func (*UUIDValidator) Name

func (s *UUIDValidator) Name() string

Name provides access to the name field

type ValidateGenerator

type ValidateGenerator struct {
	Generators map[string]Generater
}

ValidateGenerator holds a map of identifiers and Generator's

func NewValidateGenerator

func NewValidateGenerator() *ValidateGenerator

NewValidateGenerator creates a new pointer value of type ValidateGenerator - Hex: checks if a string is a valid hexadecimal format number - Length: takes 1 integer argument and compares the length of a string field against that - NotNil: Validate fails if field is nil - Set: Validate fails if field is not in a specific set of values - NotEqual: Validate fails if field is equal to specific value - UUID: Checks and fails if a string is not a valid UUID

func (*ValidateGenerator) AddValidation

func (s *ValidateGenerator) AddValidation(g Generater) error

AddValidation adds a Validation to a ValidateGenerator, that Validation can be applied to a struct field using the string returned by validator.Name()

func (*ValidateGenerator) Generate

func (s *ValidateGenerator) Generate(out io.Writer, i interface{}) error

Generate generates Validate method for a structure Implicitly generates code that validates Structs, Slices and Maps which can be nested. Null pointer fields are considered valid by default Return value of generated function is an ErrorMap of ErrorSlices, where each element of an ErrorSlice represents a failed validation

type ValidationCommand

type ValidationCommand struct {
	Params []string
	// contains filtered or unexported fields
}

ValidationCommand holds the ValidationCommand state

func NewValidationCommand

func NewValidationCommand(n string) ValidationCommand

NewValidationCommand creates a new value of type ValidationCommand

func ParseTag

func ParseTag(interf interface{}, tag string) ([]ValidationCommand, error)

ParseTag parses given struct tags

func (*ValidationCommand) Name

func (s *ValidationCommand) Name() string

Name provides access to the name field

Jump to

Keyboard shortcuts

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