datatype

package module
v0.0.0-...-e899e31 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 19 Imported by: 0

README

datatype

datatype

Documentation

Index

Constants

View Source
const (
	DateTimeTZFormat = time.DateTime + "-07:00"
)

Variables

View Source
var EncryptOptions = EncryptConfig{
	Service: DefaultEncryptService{},
}
View Source
var StorageOptions = StorageConfig{
	Signatured: false,
	BucketName: "app",
	Expired:    5 * time.Minute,
	Cache:      cache.New(5*time.Minute, 10*time.Minute),
}
View Source
var (
	TimeZone = "Asia/Shanghai"
)

Functions

func HMacSha256

func HMacSha256(key []byte, data []byte) string

HMacSha256

func LocalTimeZone

func LocalTimeZone() *time.Location

func ParseDateTime

func ParseDateTime(layout string, value string) (*time.Time, error)

func ReverseString

func ReverseString(s string) string

字符串反转

Types

type Choice

type Choice struct {
	Code  uint8  `json:"code" validate:"required"`
	Value string `json:"value"`
}

type ChoiceType

type ChoiceType struct {
	Choice Choice `json:"choice" validate:"required"`
	Meta   []Choice
}

func (ChoiceType) MarshalJSON

func (c ChoiceType) MarshalJSON() ([]byte, error)

JSON

func (*ChoiceType) Scan

func (c *ChoiceType) Scan(value any) error

GORM

func (ChoiceType) String

func (c ChoiceType) String() string

String

func (*ChoiceType) UnmarshalJSON

func (c *ChoiceType) UnmarshalJSON(data []byte) error

func (*ChoiceType) Update

func (c *ChoiceType) Update(code uint8) bool

Update

func (ChoiceType) Value

func (c ChoiceType) Value() (driver.Value, error)

type Coordinate

type Coordinate struct {
	Longitude float64 `json:"longitude" validate:"required"`
	Latitude  float64 `json:"latitude" validate:"required"`
}

func (Coordinate) GormDataType

func (c Coordinate) GormDataType() string

GORM

func (Coordinate) GormValue

func (c Coordinate) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (*Coordinate) Scan

func (c *Coordinate) Scan(value any) error

type Date

type Date time.Time

func NewDate

func NewDate(t *time.Time) Date

func (Date) GormDBDataType

func (d Date) GormDBDataType(db *gorm.DB, field *schema.Field) string

GORM

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

JSON

func (*Date) Scan

func (d *Date) Scan(value any) error

func (Date) String

func (d Date) String() string

String

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (Date) Value

func (d Date) Value() (driver.Value, error)

type DateTime

type DateTime time.Time

func NewDateTime

func NewDateTime(t *time.Time) DateTime

func (DateTime) GormDBDataType

func (dt DateTime) GormDBDataType(db *gorm.DB, field *schema.Field) string

GORM

func (DateTime) GormValue

func (dt DateTime) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

JSON

func (*DateTime) Scan

func (dt *DateTime) Scan(value any) error

func (DateTime) String

func (dt DateTime) String() string

String

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(data []byte) error

type DefaultEncryptService

type DefaultEncryptService struct{}

默认加密服务

func (DefaultEncryptService) Decode

func (es DefaultEncryptService) Decode(value string) string

func (DefaultEncryptService) Encode

func (es DefaultEncryptService) Encode(value string) string

func (DefaultEncryptService) Mask

func (es DefaultEncryptService) Mask(value string) string

type Encrypt

type Encrypt string

func (Encrypt) Mask

func (e Encrypt) Mask() string

func (*Encrypt) Scan

func (e *Encrypt) Scan(value any) error

GORM

func (Encrypt) String

func (e Encrypt) String() string

String

func (Encrypt) Value

func (e Encrypt) Value() (driver.Value, error)

type EncryptConfig

type EncryptConfig struct {
	// 加密服务
	Service EncryptService
}

type EncryptService

type EncryptService interface {
	Encode(value string) string
	Decode(value string) string
	Mask(value string) string
}

type JSON

type JSON map[string]any

func (JSON) GormDBDataType

func (j JSON) GormDBDataType(db *gorm.DB, field *schema.Field) string

GORM

func (JSON) GormValue

func (j JSON) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (*JSON) Scan

func (j *JSON) Scan(value any) error

func (JSON) String

func (j JSON) String() string

String

type JSONQueryExpression

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

func JSONQuery

func JSONQuery(column string) *JSONQueryExpression

Query

func (*JSONQueryExpression) Build

func (jsonQuery *JSONQueryExpression) Build(builder clause.Builder)

Build

func (*JSONQueryExpression) Equals

func (jsonQuery *JSONQueryExpression) Equals(value any, keys ...string) *JSONQueryExpression

Equals

func (*JSONQueryExpression) Extract

func (jsonQuery *JSONQueryExpression) Extract(path string) *JSONQueryExpression

Extract

func (*JSONQueryExpression) HasKey

func (jsonQuery *JSONQueryExpression) HasKey(keys ...string) *JSONQueryExpression

HasKey

type Password

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

func (*Password) Compare

func (p *Password) Compare(password string) bool

Compare

func (Password) MarshalJSON

func (p Password) MarshalJSON() ([]byte, error)

JSON

func (*Password) Scan

func (p *Password) Scan(value any) error

GORM

func (Password) String

func (p Password) String() string

String

func (*Password) UnmarshalJSON

func (p *Password) UnmarshalJSON(data []byte) error

func (*Password) Update

func (p *Password) Update(password string)

Update

func (Password) Value

func (p Password) Value() (driver.Value, error)

type RegexpPair

type RegexpPair struct {
	Value string
	Match bool
}

func RegexpSplit

func RegexpSplit(expr string, str string) []RegexpPair

正则表达式分割字符串

type Storage

type Storage string

func (Storage) BindSignature

func (s Storage) BindSignature() string

BindSignature

func (Storage) GetStorageToken

func (s Storage) GetStorageToken() string

GetStorageToken

func (*Storage) Scan

func (s *Storage) Scan(value any) error

GORM

func (Storage) String

func (s Storage) String() string

String

func (Storage) UnBindSignature

func (s Storage) UnBindSignature() string

UnBindSignature

func (Storage) UploadFile

func (s Storage) UploadFile(data []byte) string

UploadFile

func (Storage) Value

func (s Storage) Value() (driver.Value, error)

type StorageConfig

type StorageConfig struct {
	// 是否签名
	Signatured bool
	// 服务器URL
	ServerURL string
	// Bucket名称
	BucketName string
	// 访问Key
	AccessKey string
	// 签名Key
	SignatureKey string
	// 过期时间
	Expired time.Duration
	// 缓存
	Cache *cache.Cache
	// 存储服务
	Service StorageService
}

func (StorageConfig) HasSignature

func (c StorageConfig) HasSignature() bool

type StorageService

type StorageService interface {
	GetToken(config StorageConfig) string
	UploadFile(data []byte, token string, config StorageConfig) string
}

type Time

type Time time.Time

func NewTime

func NewTime(t *time.Time) Time

func (Time) GormDBDataType

func (t Time) GormDBDataType(db *gorm.DB, field *schema.Field) string

GORM

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

JSON

func (*Time) Scan

func (t *Time) Scan(value any) error

func (Time) String

func (t Time) String() string

String

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

func (Time) Value

func (t Time) Value() (driver.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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