serializers

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SerializerKeyRequired  = "required"
	SerializerKeyReadOnly  = "read_only"
	SerializerKeyWriteOnly = "write_only"
	SerializerKeyAllowNull = "allow_null"
)

Variables

This section is empty.

Functions

func FitSerializerData

func FitSerializerData(serializer interface{}) interface{}

func GenericValidate

func GenericValidate(serializer SerializersInterface) (bool, map[string][]string)

func InitValuesModel

func InitValuesModel(serializer SerializersInterface) models.BaseModelInterface

func MarshallSerializer

func MarshallSerializer(serializer interface{}) ([]byte, error)

func VaidatorLengthParam

func VaidatorLengthParam(minLength int, maxLength int) func(*ValidateParams)

func VaidatorRequiredParam

func VaidatorRequiredParam(required bool) func(*ValidateParams)

func ValidateInt

func ValidateInt(val int, opts ...ValidateFuncOption) (bool, []string)

func ValidateString

func ValidateString(val string, opts ...ValidateFuncOption) (bool, []string)

func ValidatorEmailParam

func ValidatorEmailParam() func(*ValidateParams)

Types

type ErrorMessage

type ErrorMessage string
const (
	StringLengthExceeded ErrorMessage = "String length exceeded"
)

type Rules

type Rules struct {
	Required  bool
	ReadOnly  bool
	WriteOnly bool
	AllowNull bool
	Validator []func(interface{}) bool
}

type Serializer

type Serializer struct {
	InstanceModel models.BaseModelInterface `json:"-" gorm:"-"`
	// contains filtered or unexported fields
}

func (*Serializer) AddError

func (s *Serializer) AddError(field string, err ...string)

func (*Serializer) Data

func (s *Serializer) Data() map[string]interface{}

func (*Serializer) Errors

func (s *Serializer) Errors() map[string][]string

func (*Serializer) GetInstanceModel

func (s *Serializer) GetInstanceModel() models.BaseModelInterface

func (*Serializer) GetModel

func (s *Serializer) GetModel() models.BaseModelInterface

func (*Serializer) SetError

func (s *Serializer) SetError(err string)

func (*Serializer) Validate

func (s *Serializer) Validate() bool

type SerializerModels

type SerializerModels interface {
	SerializersInterface
	models.BaseModelInterface
}

type SerializersInterface

type SerializersInterface interface {
	Validate() bool
	Data() map[string]interface{}
	AddError(field string, err ...string)
	SetError(err string)
	GetModel() models.BaseModelInterface
	GetInstanceModel() models.BaseModelInterface
	Errors() map[string][]string
}

type ValidateFuncOption

type ValidateFuncOption func(vp *ValidateParams)

type ValidateParams

type ValidateParams struct {
	Max       int
	Min       int
	MaxLength int
	MinLength int
	Required  bool
	Functions []func(interface{}) (bool, string)
}

Jump to

Keyboard shortcuts

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