model

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFields

func ValidateFields(fields []*FieldData) error

ValidateFields checks string parameters passed to it and returns error in case of blank values.

func ValidateParams

func ValidateParams(params map[string]interface{}) error

ValidateParams checks string parameters passed to it and returns error in case of blank values.

func ValidateString

func ValidateString(value string, constraint ConstraintType, constraintData interface{}) (bool, error)

ValidateString checks whether the given data conforms to the given constraint. Valid constraints are AlphaNumeric, AlphaNumericAndHyphen, Email, URL and RegEx. If the given constraint is RegEx, then the constraintData should contain a valid regular expression.

Types

type Base

type Base struct {
	ID        uuid.UUID  `gorm:"type:varchar(36);primary_key;"`
	CreatedAt time.Time  `gorm:"column:createdOn"`
	UpdatedAt time.Time  `gorm:"column:modifiedOn"`
	DeletedAt *time.Time `sql:"index" gorm:"column:deletedOn"`
}

Base contains common columns for all tables.

type ConstraintDetail

type ConstraintDetail struct {
	Type           ConstraintType
	ConstraintData interface{}
}

ConstraintDetail respresents constraint detail

type ConstraintType

type ConstraintType string

ConstraintType represents the type of the string

const (
	// AlphaNumeric represents string containing only alphabets and numbers
	AlphaNumeric ConstraintType = "AlphaNumeric"
	// AlphaNumericAndHyphen represents string containing alphabets, numbers and hyphen
	AlphaNumericAndHyphen ConstraintType = "AlphaNumericAndHyphen"
	// Email represents string containing email address
	Email ConstraintType = "Email"
	// RegEx represents string containing regular expression
	RegEx ConstraintType = "RegEx"
	// In represents string value from a pre-defined set
	In ConstraintType = "In"
	// URL represents string containing URL
	URL ConstraintType = "URL"
	// UUID represents string containing UUID
	UUID ConstraintType = "UUID"
)

type FieldData

type FieldData struct {
	Name        string
	Value       interface{}
	Type        string
	Required    bool
	Constraints []*ConstraintDetail
}

FieldData represents the data associated with a field

func NewStringFieldData

func NewStringFieldData(name string, value interface{}) *FieldData

NewStringFieldData creates new FieldData with type string and no constraint

func NewStringFieldDataWithConstraint

func NewStringFieldDataWithConstraint(name string, value interface{}, required bool, constraints []*ConstraintDetail) *FieldData

NewStringFieldDataWithConstraint creates new FieldData with type string and constraint

type TenantBase

type TenantBase struct {
	ID        uuid.UUID  `gorm:"type:varchar(36);primary_key;"`
	TenantID  uuid.UUID  `gorm:"type:varchar(36);column:tenantId;index:tenantid"`
	CreatedAt time.Time  `gorm:"column:createdOn;index:createdon"`
	UpdatedAt time.Time  `gorm:"column:modifiedOn"`
	DeletedAt *time.Time `sql:"index" gorm:"column:deletedOn"`
}

TenantBase contains common columns for all tables that are tenant specific.

Jump to

Keyboard shortcuts

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