Documentation
¶
Index ¶
- Constants
- Variables
- func AddConversion[TIn any, TOut any](converter model.Converter)
- func Clone[T interface{}](src T) (T, error)
- func Copy(src, dest any) error
- func EtagPtrValidateRule(field **Etag, isRequired bool) *val.FieldRules
- func EtagValidateRule(field *Etag, isRequired bool) *val.FieldRules
- func ExtractJsonName(field reflect.StructField) string
- func IdPtrValidateRule(field **Id, isRequired bool) *val.FieldRules
- func IdValidateRule(field *Id, isRequired bool) *val.FieldRules
- func IdValidateRuleMulti(field *[]Id, isRequired bool, minLength int, maxLength int) *val.FieldRules
- func IndirectValue(obj any) reflect.Value
- func IsBCP47LanguageCode(src string) bool
- func LangJsonPtrValidateRule(field **LangJson, isRequired bool, minLength int, maxLength int) *val.FieldRules
- func LanguageCodePtrValidateRule(field **LanguageCode, isRequired bool) *val.FieldRules
- func MustCopy(src, dest any)
- func NonNilFields(obj any, action func(reflect.StructField, reflect.Value))
- func Sanitize(target any)
- func SlugPtrValidateRule(field **Slug, isRequired bool) *val.FieldRules
- func SlugValidateRule(field *Slug, isRequired bool) *val.FieldRules
- func TagsOfNonNilKeys(obj any) []string
- func TagsOfNonNilKeysMap(obj any) map[string]any
- func ToBCP47LanguageCode(src string) (string, error)
- func ToMap(src any) (map[string]any, error)
- type AuditableBase
- func (this *AuditableBase) GetCreatedAt() *time.Time
- func (this *AuditableBase) GetUpdatedAt() *time.Time
- func (this *AuditableBase) SetCreatedAt(createdAt time.Time)
- func (this *AuditableBase) SetUpdatedAt(updatedAt time.Time)
- func (this *AuditableBase) ValidateRules(forEdit bool) []*val.FieldRules
- type Etag
- type Id
- type LangJson
- func (this LangJson) IsEqual(target LangJson) bool
- func (this LangJson) Normalize(enabled []LanguageCode) LangJson
- func (this LangJson) RemoveTranslationKey()
- func (this LangJson) SanitizeClone(whitelistLangs []LanguageCode, isRichText bool) (*LangJson, int, error)
- func (this LangJson) SetTranslationKey(key TranslationKey)
- func (this LangJson) TextIn(lang LanguageCode) string
- func (this LangJson) Transform(fn func(key LanguageCode, value string) string) LangJson
- func (this LangJson) TranslationKey() TranslationKey
- type LanguageCode
- type LanguagePack
- type LanguageTranslation
- type LanguageTranslationItem
- type ModelBase
- type ModelDate
- func (this ModelDate) After(t ModelDate) bool
- func (this ModelDate) AfterT(t time.Time) bool
- func (this ModelDate) Before(t ModelDate) bool
- func (this ModelDate) BeforeT(t time.Time) bool
- func (this ModelDate) Calc(fn func(t time.Time) time.Time) ModelDate
- func (this ModelDate) GoTime() time.Time
- func (this ModelDate) MarshalText() ([]byte, error)
- func (this ModelDate) String() string
- func (this *ModelDate) UnmarshalText(data []byte) error
- type ModelDateTime
- func (this ModelDateTime) After(t ModelDateTime) bool
- func (this ModelDateTime) AfterT(t time.Time) bool
- func (this ModelDateTime) Before(t ModelDateTime) bool
- func (this ModelDateTime) BeforeT(t time.Time) bool
- func (this ModelDateTime) Calc(fn func(t time.Time) time.Time) ModelDateTime
- func (this ModelDateTime) GoTime() time.Time
- func (this ModelDateTime) MarshalText() ([]byte, error)
- func (this ModelDateTime) String() string
- func (this *ModelDateTime) UnmarshalText(data []byte) error
- type ModelTime
- func (this ModelTime) After(t ModelTime) bool
- func (this ModelTime) AfterT(t time.Time) bool
- func (this ModelTime) Before(t ModelTime) bool
- func (this ModelTime) BeforeT(t time.Time) bool
- func (this ModelTime) Calc(fn func(t time.Time) time.Time) ModelTime
- func (this ModelTime) GoTime() time.Time
- func (this ModelTime) MarshalText() ([]byte, error)
- func (this ModelTime) String() string
- func (this *ModelTime) UnmarshalText(data []byte) error
- type OrgBase
- type Slug
- type TraceableBase
- type TranslationKey
- type UUID
Constants ¶
const ( MODEL_RULE_ID_ARR_MAX = 100 MODEL_RULE_COMMENT_LENGTH = 1000 MODEL_RULE_CURRENCY_SCALE = 2 MODEL_RULE_CURRENCY_MAX = math.MaxFloat64 MODEL_RULE_DESC_LENGTH = 3000 MODEL_RULE_ETAG_MIN_LENGTH = 7 MODEL_RULE_ETAG_MAX_LENGTH = 30 MODEL_RULE_FIELDS_LENGTH_MAX = 50 MODEL_RULE_FIELDS_LENGTH_MIN = 2 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 )
const ( LanguageCodeEnUs = LanguageCode("en-US") LanguageCodeViVn = LanguageCode("vi-VN") DefaultLanguageCode = LanguageCodeViVn // When this Reference Key is specified in a LangJson, all other keys are ignored. // LanguageCodeRef = LanguageCode("$ref") )
Variables ¶
var ModelRuleCodeName = val.RegExp(regexp.MustCompile(`^[a-zA-Z0-9_]+$`))
var ModelRuleModuleLogicalName = val.RegExp(regexp.MustCompile(`^[a-zA-Z0-9_.]+$`))
Logical installed-module id: short names (core, apptrait) or namespaced (nikkierp.identity).
var ZeroTime = time.Time{}
Functions ¶
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 IndirectValue ¶
func IsBCP47LanguageCode ¶
func LangJsonPtrValidateRule ¶
func LanguageCodePtrValidateRule ¶
func LanguageCodePtrValidateRule(field **LanguageCode, isRequired bool) *val.FieldRules
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 SlugPtrValidateRule ¶
func SlugPtrValidateRule(field **Slug, isRequired bool) *val.FieldRules
func SlugValidateRule ¶
func SlugValidateRule(field *Slug, isRequired bool) *val.FieldRules
func TagsOfNonNilKeys ¶
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 ¶
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 ¶
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 LangJson ¶
type LangJson map[LanguageCode]string
func NewLangJsonRef ¶
func NewLangJsonRef(key TranslationKey) LangJson
func NewLangJsonRefSf ¶
func (LangJson) Normalize ¶
func (this LangJson) Normalize(enabled []LanguageCode) LangJson
Normalize returns a copy in which every supported language holds a translation.
Keys are canonicalized to BCP47 and those outside `enabled` are dropped; a nil `enabled` means the supported set is unknown, so nothing is dropped and only the keys present are filled. Codes are processed in sorted order, and an empty one copies the nearest filled code before it, else the nearest after it. Go maps and jsonb keep no key order, so the sort is a processing order only.
A value referencing a translation key ($ref) or holding no key is returned as is, and one with no supported translation is only stripped: there is nothing to copy from, and `{}` must stay `{}` so a required check can still refuse it.
func (LangJson) RemoveTranslationKey ¶
func (this LangJson) RemoveTranslationKey()
func (LangJson) SanitizeClone ¶
func (this LangJson) SanitizeClone(whitelistLangs []LanguageCode, isRichText bool) (*LangJson, int, error)
SanitizeClone sanitizes the LangJson by removing the keys that are not in the whitelist and sanitizing the values.
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) TextIn ¶
func (this LangJson) TextIn(lang LanguageCode) string
TextIn picks the text to show in `lang`: that language, then DefaultLanguageCode, then en-US, then the lowest-sorted language holding text. A `$ref` value is a translation key, never a text, so it is skipped; an empty string means no language holds text.
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 LanguagePack ¶
type LanguagePack map[string]LanguageTranslation
Map from module name to language translation
type LanguageTranslation ¶
type LanguageTranslation map[LanguageCode]LanguageTranslationItem
Map from language code to translation items
type LanguageTranslationItem ¶
Map from keys to translation texts
type ModelBase ¶
func (*ModelBase) SetDefaults ¶
func (this *ModelBase) SetDefaults()
func (*ModelBase) ValidateRules ¶
func (this *ModelBase) ValidateRules(forEdit bool) []*val.FieldRules
type ModelDate ¶
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 WrapModelDate ¶
func (ModelDate) Calc ¶
Calc invokes `fn` with this inner `time.Time` to do some stuff, then return the new `time.Time` to wrap in a new ModelDate.
func (ModelDate) MarshalText ¶
func (*ModelDate) UnmarshalText ¶
type ModelDateTime ¶
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 WrapModelDateTime ¶
func WrapModelDateTime(t time.Time) ModelDateTime
func (ModelDateTime) After ¶
func (this ModelDateTime) After(t ModelDateTime) bool
func (ModelDateTime) Before ¶
func (this ModelDateTime) Before(t ModelDateTime) bool
func (ModelDateTime) Calc ¶
func (this ModelDateTime) Calc(fn func(t time.Time) time.Time) ModelDateTime
Calc invokes `fn` with this inner `time.Time` to do some stuff, then return the new `time.Time` to wrap in a new ModelDateTime.
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 ¶
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 WrapModelTime ¶
func (ModelTime) Calc ¶
Calc invokes `fn` with this inner `time.Time` to do some stuff, then return the new `time.Time` to wrap in a new ModelTime.
func (ModelTime) MarshalText ¶
func (*ModelTime) UnmarshalText ¶
type OrgBase ¶
type OrgBase struct {
OrgId Id `json:"orgId,omitempty"`
}
func (*OrgBase) ValidateRules ¶
func (this *OrgBase) ValidateRules(forEdit bool) []*val.FieldRules
type TraceableBase ¶
type TraceableBase struct {
CreatedBy *Id `json:"created_by,omitempty"`
}
func (*TraceableBase) GetCreatedBy ¶
func (this *TraceableBase) GetCreatedBy() *Id
func (*TraceableBase) SetCreatedBy ¶
func (this *TraceableBase) SetCreatedBy(createdBy Id)
func (*TraceableBase) ValidateRules ¶
func (this *TraceableBase) ValidateRules(forEdit bool) []*val.FieldRules
type TranslationKey ¶
type TranslationKey = string