domain

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 6 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompleteFormService

type CompleteFormService interface {
	FormDataProvider
	FormDataDecoder
	FormDataValidator
}

CompleteFormService is interface for defining all form services which can acts as provider, decoder and validator

type DefaultFormDataDecoder

type DefaultFormDataDecoder interface {
	FormDataDecoder
}

DefaultFormDataDecoder is interface for defining default form data decoder used in case when there is no custom form data decoder defined

type DefaultFormDataEncoder added in v1.0.1

type DefaultFormDataEncoder interface {
	FormDataEncoder
}

DefaultFormDataEncoder is interface for defining default form data encoder used in case when there is no custom form data encoder defined

type DefaultFormDataProvider

type DefaultFormDataProvider interface {
	FormDataProvider
}

DefaultFormDataProvider is interface for defining default form data provider used in case when there is no custom form data provider defined

type DefaultFormDataValidator

type DefaultFormDataValidator interface {
	FormDataValidator
}

DefaultFormDataValidator is interface for defining default form data validator used in case when there is no custom form data validator defined

type Error

type Error struct {
	// MessageKey - a key of the error message. Often used to pass to translation func in the template
	MessageKey string
	// DefaultLabel - a speaking error label. OFten used to show to end user - in case no translation exists
	DefaultLabel string
}

Error - representation of an Error Message - intended usage is to display errors in the view to the end user

type FieldValidator

type FieldValidator interface {
	// ValidatorName defines validator name used in fields' tags inside structs
	ValidatorName() string
	// ValidateField defines validation method called when field is validated
	ValidateField(ctx context.Context, fl validator.FieldLevel) bool
}

FieldValidator as interface for defining custom field validation

type Form

type Form struct {
	// Data  the form Data Struct (Forms DTO)
	Data interface{}
	// FormExtensionsData the additional form Data Structs (Forms DTO) fetched from form extensions
	FormExtensionsData map[string]interface{}
	// ValidationInfo for the form
	ValidationInfo ValidationInfo
	// contains filtered or unexported fields
}

Form as struct for storing form processing results

func NewForm

func NewForm(submitted bool, validationRules map[string][]ValidationRule) Form

NewForm returns new instance of Form struct

func (Form) GetErrorsForField

func (f Form) GetErrorsForField(name string) []Error

GetErrorsForField method which returns list of all general validation errors for specific field

func (Form) GetGeneralErrors

func (f Form) GetGeneralErrors() []Error

GetGeneralErrors method which returns list of all general validation errors

func (Form) GetValidationRules

func (f Form) GetValidationRules() map[string][]ValidationRule

GetValidationRules returns all available validation rules

func (Form) GetValidationRulesForField

func (f Form) GetValidationRulesForField(name string) []ValidationRule

GetValidationRulesForField adds option to extract validation rules for desired field in templates

func (Form) HasAnyFieldErrors

func (f Form) HasAnyFieldErrors() bool

HasAnyFieldErrors method which defines if there is any field validations error for any field

func (Form) HasErrorForField

func (f Form) HasErrorForField(name string) bool

HasErrorForField method which defines if there is any field validations error for specific field

func (Form) HasGeneralErrors

func (f Form) HasGeneralErrors() bool

HasGeneralErrors method which defines if there is any general validations error

func (Form) IsSubmitted

func (f Form) IsSubmitted() bool

IsSubmitted defines if form is submitted

func (Form) IsValid

func (f Form) IsValid() bool

IsValid defines if form data is valid

func (Form) IsValidAndSubmitted

func (f Form) IsValidAndSubmitted() bool

IsValidAndSubmitted defines if form data is valid and form is submitted

type FormDataDecoder

type FormDataDecoder interface {
	// Decode as method for transforming http request body into form data
	Decode(ctx context.Context, req *web.Request, values url.Values, formData interface{}) (interface{}, error)
}

FormDataDecoder is interface for defining all form services which process http request and transform it into form data

type FormDataEncoder added in v1.0.1

type FormDataEncoder interface {
	// Encode as method for transforming http request body into form data
	Encode(ctx context.Context, formData interface{}) (url.Values, error)
}

FormDataEncoder is interface for defining all form services which encode (previously decoded) formdata into urlValues

type FormDataProvider

type FormDataProvider interface {
	// GetFormData as method for defining form data
	GetFormData(ctx context.Context, req *web.Request) (interface{}, error)
}

FormDataProvider is interface for defining all form services which creates form data

type FormDataValidator

type FormDataValidator interface {
	// Validate as method for validating form data
	Validate(ctx context.Context, req *web.Request, validatorProvider ValidatorProvider, formData interface{}) (*ValidationInfo, error)
}

FormDataValidator is interface for defining all form services which validates form data

type FormError

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

FormError is used as wrapper for storing form error messages

func NewFormError

func NewFormError(details string) FormError

NewFormError returns new instance of error interface by defining string content of error

func NewFormErrorWithParent added in v1.1.0

func NewFormErrorWithParent(err error) FormError

NewFormErrorWithParent returns new instance of error interface by defining parent error

func NewFormErrorf

func NewFormErrorf(details string, args ...interface{}) FormError

NewFormErrorf returns new instance of error interface by defining formatted string content of error with arguments

func (FormError) Error

func (e FormError) Error() string

Error represents implementation for required method so FormError can fulfil error interface

func (FormError) Parent added in v1.1.0

func (e FormError) Parent() error

Parent returns parent error wrapped by FormError

type FormExtension

type FormExtension interface{}

FormExtension is helper interface for form extensions used for binding with dingo injector

type FormHandler

type FormHandler interface {
	// HandleUnsubmittedForm as method for returning Form instance which is not submitted
	HandleUnsubmittedForm(ctx context.Context, req *web.Request) (*Form, error)
	// HandleSubmittedForm as method for returning Form instance which is submitted via POST request
	HandleSubmittedForm(ctx context.Context, req *web.Request) (*Form, error)
	// HandleSubmittedGETForm as method for returning Form instance which is submitted via GET request
	HandleSubmittedGETForm(ctx context.Context, req *web.Request) (*Form, error)
	// HandleForm as method for returning Form instance with state depending on fact if there was form submission or not, via POST request
	HandleForm(ctx context.Context, req *web.Request) (*Form, error)
}

FormHandler is interface for defining main form processor which provider instance of Form domain

type FormService

type FormService interface{}

FormService is helper interface for form services used for binding with dingo injector

type StructValidator

type StructValidator interface {
	// StructType defines struct type which should be validated
	StructType() interface{}
	// ValidateStruct defines validation method called when struct is validated
	ValidateStruct(ctx context.Context, sl validator.StructLevel)
}

StructValidator as interface for defining custom struct validation

type ValidationInfo

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

ValidationInfo - represents the complete Validation Informations of your form. It can contain GeneralErrors and form field related errors.

func (*ValidationInfo) AddFieldError

func (vi *ValidationInfo) AddFieldError(fieldName string, messageKey string, defaultLabel string)

AddFieldError method which adds a field error with the passed field name, message key and default label

func (*ValidationInfo) AddGeneralError

func (vi *ValidationInfo) AddGeneralError(messageKey string, defaultLabel string)

AddGeneralError method which adds a general error with the passed MessageKey and DefaultLabel

func (*ValidationInfo) AppendFieldErrors

func (vi *ValidationInfo) AppendFieldErrors(fieldErrors map[string][]Error)

AppendFieldErrors method which appends all provided validation errors to field errors, without duplicating existing ones

func (*ValidationInfo) AppendGeneralErrors

func (vi *ValidationInfo) AppendGeneralErrors(errs []Error)

AppendGeneralErrors method which appends all provided validation errors to general errors, without duplicating existing ones

func (*ValidationInfo) GetErrorsForAllFields

func (vi *ValidationInfo) GetErrorsForAllFields() map[string][]Error

GetErrorsForAllFields method which returns list of all field validation errors for all fields

func (*ValidationInfo) GetErrorsForField

func (vi *ValidationInfo) GetErrorsForField(fieldName string) []Error

GetErrorsForField method which returns list of all general validation errors for specific field

func (*ValidationInfo) GetGeneralErrors

func (vi *ValidationInfo) GetGeneralErrors() []Error

GetGeneralErrors method which returns list of all general validation errors

func (*ValidationInfo) GetValidationSummary

func (vi *ValidationInfo) GetValidationSummary() string

GetValidationSummary - returns a string with all validation messages - useful for logging or other summarized needs

func (*ValidationInfo) HasAnyFieldErrors

func (vi *ValidationInfo) HasAnyFieldErrors() bool

HasAnyFieldErrors method which defines if there is any field validations error for any field

func (*ValidationInfo) HasErrorsForField

func (vi *ValidationInfo) HasErrorsForField(fieldName string) bool

HasErrorsForField method which defines if there is any field validations error for specific field

func (*ValidationInfo) HasGeneralErrors

func (vi *ValidationInfo) HasGeneralErrors() bool

HasGeneralErrors method which defines if there is any general validations error

func (*ValidationInfo) IsValid

func (vi *ValidationInfo) IsValid() bool

IsValid method which defines if validation info is related to valid data or not

func (ValidationInfo) MarshalJSON

func (vi ValidationInfo) MarshalJSON() ([]byte, error)

MarshalJSON - implements MarshalJson interface - so that we can use response

func (*ValidationInfo) RemoveAllFieldError

func (vi *ValidationInfo) RemoveAllFieldError(fieldName string)

RemoveAllFieldError method which removes field errors again

type ValidationRule

type ValidationRule struct {
	// Name validator tag name
	Name string
	// Value additional parameter provided as condition for validation tag
	Value string
}

ValidationRule - contains single validation rule for field. Name is mandatory (required|email|max|len|...), Value is optional and adds additional info (like "128" for "max=128" rule)

type ValidatorProvider

type ValidatorProvider interface {
	// Validate method which validates any struct and returns domain.ValidationInfo as a result of validation
	Validate(ctx context.Context, req *web.Request, value interface{}) ValidationInfo
	// GetValidator method which returns instance of validator.Validate struct with all injected field and struct validations
	GetValidator() *validator.Validate
	// ErrorsToValidationInfo method which transforms errors into domain.ValidationInfo
	ErrorsToValidationInfo(err error) ValidationInfo
}

ValidatorProvider as interface for defining main validator provider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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