utils

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DateTimeTemplate 日期时间模板
	DateTimeTemplate  = "2006-01-02 15:04:05"
	ZeroTimeTemplate  = "2006-01-02 00:00:00"
	DateTemplate      = "2006-01-02"
	OnlyTimeTemplate  = "15:04:05"
	ParseTimeTemplate = "2006-01-02T15:04:05+08:00"
	YearMonthTemplate = "2006-01"
)
View Source
const DateFormat = "2006-01-02"

DateFormat

View Source
const MonthFormat = "2006-01"

MonthFormat 月份模板

Variables

This section is empty.

Functions

func ApiSign

func ApiSign(url string, secret string) string

func Average

func Average(xs []float64) (avg float64)

Average 球平局数

func Camel2Case added in v0.2.1

func Camel2Case(name string) string

Camel2Case 驼峰式写法转为下划线写法

func Case2Camel added in v0.2.1

func Case2Camel(name string) string

Case2Camel 下划线写法转为驼峰写法

func CatchErr

func CatchErr(err error, errCode fmt.Stringer) bool

func CheckErr

func CheckErr(err error) bool

func ConvertStringUTC

func ConvertStringUTC(t string) string

ConvertStringUTC UTC 时间转换

func ConvertUTC

func ConvertUTC(t time.Time) string

ConvertUTC UTC 时间转换

func DebugResponse

func DebugResponse(err error, errCode fmt.Stringer, debugMsg string)

func Decimal

func Decimal(value float64) float64

Decimal 保留2位小数

func GetApiServer

func GetApiServer(url string) string

func GetDayRangeList

func GetDayRangeList(startDate string, endDate string) ([]string, error)

GetDayRangeList 获取日期区间数据

func GetDayStringSub

func GetDayStringSub(startDate string, endDate string) int

GetDayStringSub 获取两个日期的天数之差

func GetDaySub

func GetDaySub(startDate time.Time, endDate time.Time) int

GetDaySub 获取日期差天数

func GetGenerator added in v0.2.3

func GetGenerator(db *gorm.DB) *gen.Generator

GetGenerator 获取生成器

func GetGeneratorOptions added in v0.2.3

func GetGeneratorOptions() []gen.ModelOpt

func GetImgBase64String

func GetImgBase64String(image string) (string, error)

func GetMonthRangeList

func GetMonthRangeList(startDate string, endDate string) []string

GetMonthRangeList 月份区间

func GetStructField

func GetStructField(ptr any) []string

func GetStructMap

func GetStructMap(data any) map[string]any

func GetTimeDuration

func GetTimeDuration(startTime int64, endTime int64) int64

GetTimeDuration 获取时间区间

func GetWeekRangeList

func GetWeekRangeList(startDate string, endDate string) []string

GetWeekRangeList 将开始时间和结束时间分割为周为单位

func GetYearDay

func GetYearDay(date time.Time) int

GetYearDay 获取一年中的第几天

func HasErr

func HasErr(err error, errCode fmt.Stringer) bool

func HasQueryErr

func HasQueryErr(err error, errCode fmt.Stringer) bool

HasQueryErr 数据库查询异常

func HasWar

func HasWar(err error, errCode fmt.Stringer) bool

func IsStaticRequest

func IsStaticRequest(context *gin.Context) bool

IsStaticRequest 判断是否是静态文件请求

func JsonDisplay

func JsonDisplay(obj any)

func JsonString

func JsonString(params any) string

func LcFirst added in v0.2.1

func LcFirst(str string) string

LcFirst 首字母小写

func MaxNum

func MaxNum(arr []int) (max int, maxIndex int)

func MinNum

func MinNum(arr []int) (min int, minIndex int)

func OpenFreeUDPPort

func OpenFreeUDPPort(portBase int, num int) (net.PacketConn, int, error)

OpenFreeUDPPort opens free UDP port This example does not actually use UDP ports, but to avoid port collisions with the HTTP server, it binds the same number of UDP port in advance.

func RandString

func RandString(length int) string

func RequestSign

func RequestSign(ts string, secret string) string

func RpcSign

func RpcSign(secret string) (string, int64)

func SetStructField

func SetStructField(ptr any, fields map[string]string)

func Sign

func Sign(params map[string]any, secret string) string

Sign 接口请求签名

func SignParams

func SignParams(paramsStruct any, secret string) map[string]any

Sign 接口请求签名

func Success

func Success(status int) bool

func ToHump

func ToHump(str string) string

func ToLine

func ToLine(str string) string

func TransDateArr

func TransDateArr(start string, end string) []string

TransDateArr 获取日期区间

func TransDateFormat

func TransDateFormat(dateTime string, template string) (string, error)

TransDateFormat 时间日期转换

func TransInterfaceToMap

func TransInterfaceToMap(params any) map[string]any

TransInterfaceToMap 转换struct 等结构到map

func TransJsonString added in v0.2.1

func TransJsonString(source []byte) []byte

func TransStrToImage

func TransStrToImage(sourceString string, imageName string) error

TransStrToImage base64 字符串转图片

func TransStruct added in v0.2.4

func TransStruct[T any](source any, target T) error

TransStruct 转换struct

func TransToByte

func TransToByte(params any) []byte

func UcFirst

func UcFirst(str string) string

UcFirst 首字母大写

Types

type Buffer added in v0.2.1

type Buffer struct {
	*bytes.Buffer
}

Buffer 内嵌bytes.Buffer,支持连写

func NewBuffer added in v0.2.1

func NewBuffer() *Buffer

func (*Buffer) Append added in v0.2.1

func (b *Buffer) Append(i interface{}) *Buffer

type ImageUtil

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

func NewImageUtil

func NewImageUtil() *ImageUtil

func (*ImageUtil) Resize

func (i *ImageUtil) Resize() error

func (*ImageUtil) SetImage

func (i *ImageUtil) SetImage(sourceImg string, targetImg string) *ImageUtil

func (*ImageUtil) SetSize

func (i *ImageUtil) SetSize(width int, height int) *ImageUtil

type JsonCamelCase added in v0.2.1

type JsonCamelCase struct {
	Value interface{}
}

func (JsonCamelCase) MarshalJSON added in v0.2.1

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

type JsonSnakeCase added in v0.2.1

type JsonSnakeCase struct {
	Value interface{}
}

func (JsonSnakeCase) MarshalJSON added in v0.2.1

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

func (JsonSnakeCase) UnmarshalJSON added in v0.2.1

func (c JsonSnakeCase) UnmarshalJSON(b []byte) error

type WeekDate

type WeekDate struct {
	WeekTh    string
	StartTime time.Time
	EndTime   time.Time
}

Directories

Path Synopsis
Package concurrency contain some functions to support concurrent programming.
Package concurrency contain some functions to support concurrent programming.
Package condition contains some functions for conditional judgment.
Package condition contains some functions for conditional judgment.
Package convertor implements some functions to convert data.
Package convertor implements some functions to convert data.
Package cryptor implements some util functions to encrypt and decrypt.
Package cryptor implements some util functions to encrypt and decrypt.
Package datastructure implements some data structure.
Package datastructure implements some data structure.
hashmap
Package datastructure implements some data structure.
Package datastructure implements some data structure.
heap
Package datastructure implements some data structure.
Package datastructure implements some data structure.
list
Package datastructure implements some data structure.
Package datastructure implements some data structure.
set
Package datetime implements some functions to format date and time.
Package datetime implements some functions to format date and time.
Package fileutil implements some basic functions for file operations
Package fileutil implements some basic functions for file operations
Package formatter implements some functions to format string, struct.
Package formatter implements some functions to format string, struct.
Package function implements some functions for control the function execution and some is for functional programming.
Package function implements some functions for control the function execution and some is for functional programming.
Package internal is for internal use.
Package internal is for internal use.
Package iterator provides a way to iterate over values stored in containers.
Package iterator provides a way to iterate over values stored in containers.
Package lancetconstraints contain some comstomer constraints.
Package lancetconstraints contain some comstomer constraints.
Package maputil includes some functions to manipulate map.
Package maputil includes some functions to manipulate map.
Package mathutil implements some functions for math calculation.
Package mathutil implements some functions for math calculation.
Package netutil implements some basic functions to send http request and get ip info.
Package netutil implements some basic functions to send http request and get ip info.
Package random implements some basic functions to generate random int and string.
Package random implements some basic functions to generate random int and string.
Package retry is for executing a function repeatedly until it was successful or canceled by the context.
Package retry is for executing a function repeatedly until it was successful or canceled by the context.
Package slice implements some functions to manipulate slice.
Package slice implements some functions to manipulate slice.
Package strutil implements some functions to manipulate string.
Package strutil implements some functions to manipulate string.
Package system contain some functions about os, runtime, shell command.
Package system contain some functions about os, runtime, shell command.
Package validator implements some validate function for string.
Package validator implements some validate function for string.
Package xerror implements helpers for errors
Package xerror implements helpers for errors

Jump to

Keyboard shortcuts

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