model

package
v0.0.0-...-c78e9a6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: LGPL-2.1 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODEL_RULE_ID_ARR_MAX          = 100
	MODEL_RULE_COL_LENGTH_MAX      = 50
	MODEL_RULE_COL_LENGTH_MIN      = 2
	MODEL_RULE_DESC_LENGTH         = 3000
	MODEL_RULE_ETAG_MIN_LENGTH     = 7
	MODEL_RULE_ETAG_MAX_LENGTH     = 30
	MODEL_RULE_MAX_INT16           = math.MaxInt16
	MODEL_RULE_MAX_INT64           = math.MaxInt64
	MODEL_RULE_NON_NIKKI_ID_LENGTH = 50
	MODEL_RULE_PAGE_INDEX_START    = 0
	MODEL_RULE_PAGE_INDEX_END      = math.MaxInt16
	MODEL_RULE_PAGE_DEFAULT_SIZE   = 50
	MODEL_RULE_PAGE_MAX_SIZE       = 500
	MODEL_RULE_PAGE_MIN_SIZE       = 1
	MODEL_RULE_PASSWORD_MIN_LENGTH = 8
	MODEL_RULE_PASSWORD_MAX_LENGTH = 100
	MODEL_RULE_LONG_NAME_LENGTH    = 200
	MODEL_RULE_SHORT_NAME_LENGTH   = 100
	MODEL_RULE_TINY_NAME_LENGTH    = 50
	MODEL_RULE_ULID_LENGTH         = 26
	MODEL_RULE_SLUG_LENGTH_MIN     = 3
	MODEL_RULE_SLUG_LENGTH_MAX     = MODEL_RULE_TINY_NAME_LENGTH
	MODEL_RULE_URL_LENGTH_MIN      = 10
	MODEL_RULE_URL_LENGTH_MAX      = 2000
	MODEL_RULE_USERNAME_LENGTH     = 254
)
View Source
const (
	LanguageCodeEnUS    = LanguageCode("en-US")
	DefaultLanguageCode = LanguageCodeEnUS
	// When this Label Reference is specified in a LangJson, all other keys are ignored.
	//
	LabelRefLanguageCode = LanguageCode("$ref")
)

Variables

View Source
var ModelRuleCodeName = val.RegExp(regexp.MustCompile(`^[a-zA-Z0-9_]+$`))
View Source
var ZeroTime = time.Time{}

Functions

func AddConversion

func AddConversion[TIn any, TOut any](converter model.Converter)

func Clone

func Clone[T interface{}](src T) (T, error)

Clone returns a deep clone of given object

func Copy

func Copy(src, dest any) error

func EtagPtrValidateRule

func EtagPtrValidateRule(field **Etag, isRequired bool) *val.FieldRules

func EtagValidateRule

func EtagValidateRule(field *Etag, isRequired bool) *val.FieldRules

func ExtractJsonName

func ExtractJsonName(field reflect.StructField) string

func IdPtrValidateRule

func IdPtrValidateRule(field **Id, isRequired bool) *val.FieldRules

func IdValidateRule

func IdValidateRule(field *Id, isRequired bool) *val.FieldRules

func IdValidateRuleMulti

func IdValidateRuleMulti(field *[]Id, isRequired bool, minLength int, maxLength int) *val.FieldRules

func IndirectValue

func IndirectValue(obj any) reflect.Value

func IsBCP47LanguageCode

func IsBCP47LanguageCode(src string) bool

func LangJsonPtrValidateRule

func LangJsonPtrValidateRule(field **LangJson, isRequired bool, minLength int, maxLength int) *val.FieldRules

func LanguageCodePtrValidateRule

func LanguageCodePtrValidateRule(field **LanguageCode, isRequired bool) *val.FieldRules

func MustCopy

func MustCopy(src, dest any)

func NonNilFields

func NonNilFields(obj any, action func(reflect.StructField, reflect.Value))

NonNilFields inspects given struct obj and invokes the action for each field with non-nil value.

func Sanitize

func Sanitize(target any)

func SlugPtrValidateRule

func SlugPtrValidateRule(field **Slug, isRequired bool) *val.FieldRules

func SlugValidateRule

func SlugValidateRule(field *Slug, isRequired bool) *val.FieldRules

func TagsOfNonNilKeys

func TagsOfNonNilKeys(obj any) []string

TagsOfNonNilKeys inspects given struct obj and returns JSON tag names of fields whose value is not nil. Fields with nil value are omitted.

func TagsOfNonNilKeysMap

func TagsOfNonNilKeysMap(obj any) map[string]any

TagsOfNonNilKeysMap inspects given struct obj and returns a map of JSON tag names and its not-nil values. Fields with nil value are omitted.

func ToBCP47LanguageCode

func ToBCP47LanguageCode(src string) (string, error)

func ToMap

func ToMap(src any) (map[string]any, error)

ToMap deeply converts a struct into a map[string]any

Types

type AuditableBase

type AuditableBase struct {
	CreatedAt *time.Time `json:"createdAt,omitempty"`
	UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}

func (*AuditableBase) GetCreatedAt

func (this *AuditableBase) GetCreatedAt() *time.Time

func (*AuditableBase) GetUpdatedAt

func (this *AuditableBase) GetUpdatedAt() *time.Time

func (*AuditableBase) SetCreatedAt

func (this *AuditableBase) SetCreatedAt(createdAt time.Time)

func (*AuditableBase) SetUpdatedAt

func (this *AuditableBase) SetUpdatedAt(updatedAt time.Time)

func (*AuditableBase) ValidateRules

func (this *AuditableBase) ValidateRules(forEdit bool) []*val.FieldRules

type Etag

type Etag = string

func NewEtag

func NewEtag() *Etag

type Id

type Id = string

func NewId

func NewId() (*Id, error)

type LangJson

type LangJson map[LanguageCode]string

func (LangJson) IsEqual

func (this LangJson) IsEqual(target LangJson) bool

func (LangJson) RemoveTranslationKey

func (this LangJson) RemoveTranslationKey()

func (LangJson) SanitizeClone

func (this LangJson) SanitizeClone(whitelistLangs []LanguageCode, isRichText bool) (*LangJson, int, error)

func (LangJson) SetTranslationKey

func (this LangJson) SetTranslationKey(key TranslationKey)

SetTranslationKey references this LangJson to another translation object.

WARNING: It clears all other keys in this LangJson.

func (LangJson) Transform

func (this LangJson) Transform(fn func(key LanguageCode, value string) string) LangJson

Transform creates a new LangJson with the same keys but with the values transformed by the given function.

func (LangJson) TranslationKey

func (this LangJson) TranslationKey() TranslationKey

type LanguageCode

type LanguageCode = string

LanguageCode is a BCP47-compliant language code with region part. It must be an alias of string to easily map from map[LanguageCode]string to LangJson

type ModelBase

type ModelBase struct {
	Id   *Id   `json:"id,omitempty"`
	Etag *Etag `json:"etag,omitempty"`
}

func (*ModelBase) GetEtag

func (this *ModelBase) GetEtag() *Etag

func (*ModelBase) GetId

func (this *ModelBase) GetId() *Id

func (*ModelBase) SetDefaults

func (this *ModelBase) SetDefaults()

func (*ModelBase) SetEtag

func (this *ModelBase) SetEtag(etag Etag)

func (*ModelBase) SetId

func (this *ModelBase) SetId(id Id)

func (*ModelBase) ValidateRules

func (this *ModelBase) ValidateRules(forEdit bool) []*val.FieldRules

type ModelDate

type ModelDate time.Time

A time.Time wrapper to represent a date without time. Use this to consistently handle date thoughout this application.

func NewModelDate

func NewModelDate() ModelDate

func ParseModelDate

func ParseModelDate(timestamp string) (ModelDate, error)

func (ModelDate) GoTime

func (this ModelDate) GoTime() time.Time

func (ModelDate) MarshalText

func (this ModelDate) MarshalText() ([]byte, error)

func (ModelDate) String

func (this ModelDate) String() string

func (*ModelDate) UnmarshalText

func (this *ModelDate) UnmarshalText(data []byte) error

type ModelDateTime

type ModelDateTime time.Time

A time.Time wrapper to represent a date-time. Use this to consistently handle date-time thoughout this application.

func NewModelDateTime

func NewModelDateTime() ModelDateTime

func ParseModelDateTime

func ParseModelDateTime(timestamp string) (ModelDateTime, error)

func (ModelDateTime) GoTime

func (this ModelDateTime) GoTime() time.Time

func (ModelDateTime) MarshalText

func (this ModelDateTime) MarshalText() ([]byte, error)

func (ModelDateTime) String

func (this ModelDateTime) String() string

func (*ModelDateTime) UnmarshalText

func (this *ModelDateTime) UnmarshalText(data []byte) error

type ModelTime

type ModelTime time.Time

A time.Time wrapper to represent a time without date. Use this to consistently handle time this application.

func NewModelTime

func NewModelTime() ModelTime

func ParseModelTime

func ParseModelTime(timestamp string) (ModelTime, error)

func (ModelTime) GoTime

func (this ModelTime) GoTime() time.Time

func (ModelTime) MarshalText

func (this ModelTime) MarshalText() ([]byte, error)

func (ModelTime) String

func (this ModelTime) String() string

func (*ModelTime) UnmarshalText

func (this *ModelTime) UnmarshalText(data []byte) error

type OrgBase

type OrgBase struct {
	OrgId Id `json:"orgId,omitempty"`
}

func (*OrgBase) GetOrgId

func (this *OrgBase) GetOrgId() Id

func (*OrgBase) SetOrgId

func (this *OrgBase) SetOrgId(orgId Id)

func (*OrgBase) ValidateRules

func (this *OrgBase) ValidateRules(forEdit bool) []*val.FieldRules

type Slug

type Slug = string

type TranslationKey

type TranslationKey = string

Jump to

Keyboard shortcuts

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