types

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 2 Imported by: 0

README

黑魔法类型

一些带有特殊用途的类型

JSONString

json 字符串,该类型在转成json字符串的时候,会自动转成object类型,所以要求该类型的值是一个合法的json字符串

使用场景:扩展字段

import "github.com/go-eyas/toolkit/types"

var str = types.JSONString(`{"demo": true, "num": 123}`)

data := struct {
  S JSONString
}{str}

json.Marshal(data) // {"S":{"demo":true,"num":123}}

data2 := struct{
  Demo bool
  Num int
}{}
str.JSON(&data2) // 也可以直接 json 反序列化
Time

时间类型 time.Time 的别名,该类型在转成 json 字符串的时候,会把时间格式化成这种格式 2006-01-02 15:04:05

结合 gorm 使用,存在数据库的是时间类型,转到接口的是上述时间格式

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONObj

type JSONObj map[string]interface{}

JSONObj json 对象, 序列化的时候,变成纯字符串

func (JSONObj) JSON

func (m JSONObj) JSON(v interface{}) error

func (JSONObj) String

func (m JSONObj) String() JSONString

type JSONString

type JSONString string

JSONString json 字符串 在json序列化的时候,会把json字符串转成 object

func (JSONString) JSON

func (s JSONString) JSON(v interface{}) error

func (JSONString) MarshalJSON

func (s JSONString) MarshalJSON() ([]byte, error)

MarshalJSON 格式化为json字符串的时候,会格式化成 object

type Time

type Time time.Time

Time 时间别名,在json序列化的时候,会格式成 2006-01-02 15:04:05 这种时间格式

func (Time) MarshalJSON

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

Jump to

Keyboard shortcuts

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