datatypes

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 3 Imported by: 0

README

gorm_struct_warpper

gorm 解析 struct 的 warpper

用法

// map解析成struct
type demomap struct {
	GObj `json:"-"`
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func (o *demomap) Scan(value interface{}) error {
	return o.GObj.Scan(value, &o)
}

func (o demomap) Value() (driver.Value, error) {
	return o.GObj.Value(o)
}

// 列表解析成struct
type demolist struct {
	GObj `json:"-"`
	list []string
}

func (o *demolist) At(index int) string {
	return o.list[index]
}

func (o *demolist) Scan(value interface{}) error {
	return o.GObj.Scan(value, &o.list)
}

func (o demolist) Value() (driver.Value, error) {
	return o.GObj.Value(o.list)
}

func (o *demolist) MarshalJSON() ([]byte, error) {
	a, e := json.Marshal(&o.list)
	return a, e
}

func (o *demolist) UnmarshalJSON(b []byte) error {
	return json.Unmarshal(b, &o.list)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GObj

type GObj struct {
}

func (*GObj) GormDataType

func (o *GObj) GormDataType() string

func (*GObj) Scan

func (o *GObj) Scan(value any, obj any) error

Scan Scanner

func (GObj) Value

func (o GObj) Value(obj any) (driver.Value, error)

Value Valuer

Jump to

Keyboard shortcuts

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