goch

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 8 Imported by: 0

README

Golang的一堆代码(GoCH, Code Heap for Golang)

安装

go get -u gitee.com/gaodongchen/goch

使用

import "gitee.com/gaodongchen/goch"

type User struct {
    CreatedAt goch.Time `json:"created_at"`
}

user := &User{CreatedAt: goch.Now()}
data, _ :=json.Marshal(user)
fmt.Println(string(data))

输出:

{"created_at": "2006-01-02 15:04:05"}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSuccessCode    int    = 0
	DefaultSuccessMessage string = "success"
	DefalutErrorCode      int    = -1
)
View Source
var DefaultPageSize int = 10

默认每页数量

View Source
var ErrPriceScan = errors.New("价格类型解析失败")
View Source
var TimeDefaultLayout string = "2006-01-02 15:04:05"

时间默认格式

Functions

func Error

func Error(ctx *gin.Context, err error) *gin.Context

错误输出 兼容gapgo的errors

func Failure

func Failure(ctx *gin.Context, code int, message string) *gin.Context

func IsDuplicate added in v0.0.2

func IsDuplicate[T any, V comparable](list []T, f func(T) V) bool

IsDuplicate checks if there are any duplicates in a list of items.

func SliceMap added in v0.0.2

func SliceMap[T, U any](slice []T, fn func(T) U) []U

对一个切片执行映射操作

func Success

func Success(ctx *gin.Context, data any) *gin.Context

func ToMap

func ToMap[K comparable, V any](rows []V, f func(V) (K, V)) map[K]V

索引Map

Types

type Pagination

type Pagination struct {
	Page    int    `json:"page" form:"page"`       // 页码
	Size    int    `json:"size" form:"size"`       // 每页数量
	Keyword string `json:"keyword" form:"keyword"` // 关键字
}

分页

func (Pagination) GetPage

func (p Pagination) GetPage() int

获取正确的page信息

func (Pagination) GetSize

func (p Pagination) GetSize() int

过滤后的page size

func (Pagination) Offset

func (p Pagination) Offset() int

计算偏移值

type Price

type Price float64

价格类型

func (*Price) Scan

func (p *Price) Scan(value interface{}) error

从数据库中读取后处理

func (Price) Value

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

写入数据库的值

type Time

type Time time.Time

时间类型

func Now

func Now() Time

func (*Time) MarshalJSON

func (mt *Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

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

func (Time) Value

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

写入数据库的值

type YesOrNo

type YesOrNo int

是否

const (
	// 否,双数
	No YesOrNo = 0
	// 是,单数
	Yes YesOrNo = 1
)

func (YesOrNo) String

func (w YesOrNo) String() string

名称

func (YesOrNo) StringDIY

func (w YesOrNo) StringDIY(y, n string) string

自定义名称

Jump to

Keyboard shortcuts

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