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) RemoveTranslationKey()
- func (this LangJson) SanitizeClone(whitelistLangs []LanguageCode, isRichText bool) (*LangJson, int, error)
- func (this LangJson) SetTranslationKey(key TranslationKey)
- func (this LangJson) Transform(fn func(key LanguageCode, value string) string) LangJson
- func (this LangJson) TranslationKey() TranslationKey
- type LanguageCode
- type ModelBase
- type ModelDate
- type ModelDateTime
- type ModelTime
- type OrgBase
- type Slug
- type TranslationKey
Constants ¶
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 )
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 ¶
var ModelRuleCodeName = val.RegExp(regexp.MustCompile(`^[a-zA-Z0-9_]+$`))
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 (LangJson) RemoveTranslationKey ¶
func (this LangJson) RemoveTranslationKey()
func (LangJson) SanitizeClone ¶
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 ¶
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 (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 (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 (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 TranslationKey ¶
type TranslationKey = string