util

package
v0.0.0-...-5952180 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeMd5

func EncodeMd5(value string) string

Types

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself JSONTime类型是自定义的时间类型, 提供给 Gorm 使用. 以用来实现我们自定义的时间格式。 我们只需定义一个内嵌time.Time的结构体,并重写MarshalJSON方法,然后在定义model的时候把time.Time类型替换为我们自己的类型即可。 但是在gorm中只重写MarshalJSON是不够的,只写这个方法会在写数据库的时候会提示delete_at字段不存在。 需要加上database/sql的Value和Scan方法 https://github.com/jinzhu/gorm/issues/1611#issuecomment-329654638

func (JSONTime) MarshalJSON

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

MarshalJSON 在额外的类型上实现 json.Marshaler 以获取自定义 Time格式, 因为 go的time包中实现json.Marshaler接口时指定了使用RFC3339Nano这种格式, 但是go的方法不能重写, 所以只能自定义类型 MarshalJSON implements the json.Marshaler interface. MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan value of time.Time

func (JSONTime) Value

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

Value insert timestamp into mysql need this function.

Jump to

Keyboard shortcuts

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