hdutils

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MPL-2.0 Imports: 28 Imported by: 21

README

hdutils

Documentation

Index

Constants

View Source
const (
	DefaultPageSize = 10
)

Variables

View Source
var (
	EmptyJsonArray  = StringToBytes("[]")
	EmptyJsonObject = StringToBytes("{}")
)
View Source
var (
	DefaultTimeLocation = time.FixedZone("CST", 8*3600)
	LayoutIsoDate       = "2006-01-02"
)

Functions

func AST

func AST() aster

func AlphaNumeric

func AlphaNumeric(s string) string

AlphaNumeric 去除字符数字以外的所有字符

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Chinese

func Chinese(s string) string

Chinese 去除中文以外的所有字符

func CleanString

func CleanString(origStr string, args ...bool) string

CleanString 处理字符串, args[0]为是否转换为小写

func Contains

func Contains[T comparable](list []T, checkItem T) bool

func CsvToInt32s

func CsvToInt32s(strValue string) []int32

CsvToInt32s 将逗号分隔的string尝试转换成[1,2,3...]的int32 slice Csv means Comma Separated Value

func CsvToInt64s

func CsvToInt64s(strValue string) []int64

CsvToInt64s 将逗号分隔的string尝试转换成[1,2,3...]的int64 slice Csv means Comma Separated Value

func CsvToInts added in v0.0.4

func CsvToInts(strValue string) []int

CsvToInts 将逗号分隔的string尝试转换成[1,2,3...]的int slice Csv means Comma Separated Value

func DeltaDays

func DeltaDays(t1, t2 time.Time) int

DeltaDays 计算两个日期间的间隔天数

func FromUnixTime

func FromUnixTime(ts int64, format string) string

func GenerateRandString

func GenerateRandString(n int) string

GenerateRandString 生成随机字符串

func Get1stDayOfWeek

func Get1stDayOfWeek() string

Get1stDayOfWeek 获取本周第一天

func GetBeginUnixTS

func GetBeginUnixTS(beginDate string) int64

GetBeginUnixTS 给出字符串的日期,例如2006-01或者2006-01-02, 返回对应的时间戳

func GetBetweenDays

func GetBetweenDays(format, beginDate string, args ...string) ([]string, error)

GetBetweenDays @description 获取开始日期和结束日期中间的所有日期列表 @param beginDate string 开始时间,格式为:2020-04-01 @param args ...string 如果指定了结束时间,则用结束时间,否则用当前时间,格式为:2020-04-01 @return 在这段日期时间内的所有天包含起始日期 []string,如:[2020-04-01 2020-04-02 2020-04-03]

func GetDayBeginTimeSince

func GetDayBeginTimeSince(ts int64, ndays int) time.Time

GetDayBeginTimeSince 获取从某个时间n天后第一秒的时间, 指定时间之前的日期00:00:00时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetDayEndTime

func GetDayEndTime(ndays int) time.Time

GetDayEndTime 获取当前时间n天后最后一秒的时间, 当前时间后n天后的日期23:59:59时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetDayEndTimeSince

func GetDayEndTimeSince(ts int64, ndays int) time.Time

GetDayEndTimeSince 获取从某个时间n天后最后一秒的时间, 指定时间之前的日期23:59:59时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetEndUnixTS

func GetEndUnixTS(endDate string) int64

func GetMonthBeginTime

func GetMonthBeginTime(nmonth int) time.Time

GetMonthBeginTime 获取当前时间所在月份指定月份的第一天的开始时间, 即某月第一天的0点 如果nmonth=-1, 则是上一个月的第一天的00:00:00, 如果nmonth=0, 则是本月的第一天的00:00:00 如果nmonth=1, 则是下个月的第一天的00:00:00

func GetMonthBeginTimeSince

func GetMonthBeginTimeSince(ts int64, nmonth int) time.Time

GetMonthBeginTimeSince 获取从某个时间n个月后第一天第一秒的时间 nmonth: -1表示前一个月,0表示本月,1表示后一个月

func GetMonthEndTime

func GetMonthEndTime(nmonth int) time.Time

GetMonthEndTime 获取当前时间的指定月份的最后一天的23:59:59 即某月最后一天的23:59:59 如果nmonth=-1, 则是上一个月的最后一天的23:59:59 如果nmonth=0, 则是本月的最后一天的23:59:59 如果nmonth=1, 则是下个月的最后一天的23:59:59

func GetMonthEndTimeSince

func GetMonthEndTimeSince(ts int64, nmonth int) time.Time

GetMonthEndTimeSince 获取从某个时间n个月最后一天最后一秒的时间, 指定时间之前的日期23:59:59时间戳 nmonth: -1表示前一个月,0表示本月,1表示后一个月

func GetNeo4jPathPattern

func GetNeo4jPathPattern(args ...int32) string

GetNeo4jPathPattern 解析Neo4j语法的Variable-length pattern

func GetPagePositions

func GetPagePositions(data interface{}, pageSize int) [][]int

GetPagePositions 获取分页的起始值列表 @return 返回一个二维数组, 第一维是多少页,第二维是每页[]int{start, end} e,g: 假设11个数的列表,分页pageSize是5,那么返回的是:

[]int{
   []int{0, 5},
   []int{5, 10},
   []int{10, 11},
}

func GetSliceData

func GetSliceData(data interface{}) []interface{}

GetSliceData 将传过来的数据转换成[]interface{}

func GetStartEndPosition added in v0.0.8

func GetStartEndPosition(page, pageSize, total int64) (int64, int64)

GetStartEndPosition 如果是按列表slice进行翻页的话, 计算slice的起始index

func GetYearBeginTime

func GetYearBeginTime(nyear int) time.Time

GetYearBeginTime 获取当前时间所在年份指定年的第一天的开始时间, 即某年第一天的0点 如果nyear=-1, 则是上一年的第一天的00:00:00, 如果nyear=0, 则是本年的第一天的00:00:00 如果nyear=1, 则是下一年的第一天的00:00:00

func GetYearEndTime

func GetYearEndTime(nyear int) time.Time

GetYearEndTime 获取当前时间的指定年份的最后一天的23:59:59 即某年最后一天的23:59:59 如果nyear=-1, 则是上一个年的最后一天的23:59:59 如果nyear=0, 则是本年的最后一天的23:59:59 如果nyear=1, 则是下一年的最后一天的23:59:59

func HashBytes added in v0.0.2

func HashBytes(data []byte, length int) string

func HashId added in v0.0.7

func HashId(s string) uint32

func HashString added in v0.0.2

func HashString(s string, length int) string

func Int32sToCsv

func Int32sToCsv(int32s []int32) string

Int32sToCsv 将int32 slice转换成用逗号分隔的字符串: 1,2,3

func Int64sToCsv

func Int64sToCsv(int64s []int64) string

Int64sToCsv 将int64 slice转换成用逗号分隔的字符串: 1,2,3

func IsAlphanumeric

func IsAlphanumeric(s string) bool

IsAlphanumeric check if the string contains only letters and numbers. Empty string is valid.

func IsEmptyJsonArray added in v0.0.3

func IsEmptyJsonArray(data []byte) bool

IsEmptyJsonArray 是否是空json array

func IsEmptyJsonObject added in v0.0.3

func IsEmptyJsonObject(data []byte) bool

IsEmptyJsonObject 是否是空json object

func IsImageData

func IsImageData(data []byte) bool

IsImageData 是否是图像数据

func IsNumeric

func IsNumeric(s string) bool

IsNumeric check if the string contains only numbers. Empty string is valid.

func IsValidBeginEndTime

func IsValidBeginEndTime(strBeginTime, strEndTime string) error

IsValidBeginEndTime check if it is valid begin/end time

func IsValidMobile

func IsValidMobile(mobile string) bool

IsValidMobile check if the string is valid chinese mobile number

func JsonArray

func JsonArray(args ...any) []byte

JsonArray 将slice转换成[]byte数据,如果slice为nil或空则返回空json array bytes

func JsonObject

func JsonObject(args ...any) []byte

JsonObject 将object转换成[]byte数据,如果object为nil或空则返回空json object bytes

func LogDebug

func LogDebug(msg string, keyvals ...interface{})

func LogError

func LogError(msg string, keyvals ...interface{})

func LogFatal

func LogFatal(msg string, keyvals ...interface{})

func LogWarn

func LogWarn(msg string, keyvals ...interface{})

func NewGoFile

func NewGoFile(pkgName string, imports map[string]string) gofile

func Numeric

func Numeric(s string) string

Numeric 去除数字以外的所有字符

func ParseArgs

func ParseArgs(keyvals ...interface{}) (string, error, map[string]interface{})

ParseArgs 解析error和message用统一格式展示出来

func ParseStrTime

func ParseStrTime(value string) (*time.Time, error)

ParseStrTime iso time string转化为时间,layout必须为 "2006-01-02 15:04:05"

func RecordErrorStack

func RecordErrorStack(app string)

RecordErrorStack 将错误信息保存到错误日志文件中

func RemoveInvisibleCharacter

func RemoveInvisibleCharacter(origStr string) string

RemoveInvisibleCharacter 去除掉不能显示的字符

func ReverseInt64Slice

func ReverseInt64Slice(numbers []int64) []int64

ReverseInt64Slice 将[]int64 slice倒序重新排列

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func ToBytes

func ToBytes(value interface{}) ([]byte, error)

func ToCamelCase

func ToCamelCase(str string) string

ToCamelCase converts from underscore separated form to camel case form.

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed 浮点数到指定小数位

func ToInt32Slice

func ToInt32Slice(strSlice []string) []int32

ToInt32Slice 将string slice转换成[1,2,3...]的int32 slice

func ToInt64Slice

func ToInt64Slice(strSlice []string) []int64

ToInt64Slice 将string slice转换成[1,2,3...]的int64 slice

func ToIntSlice added in v0.0.4

func ToIntSlice(strSlice []string) []int

ToIntSlice 将string slice转换成[1,2,3...]的int slice

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts from camel case form to underscore separated form.

func ToString

func ToString(value interface{}) (string, error)

ToString 尝试将值转换成字符串

Types

type AstAnnotation

type AstAnnotation struct {
	Name  string
	Value string
}

AstAnnotation 注释中的注解

type AstFunction

type AstFunction struct {
	Receiver      string
	Function      string
	Annotations   map[string]*AstAnnotation // annotationName->*AstAnnotation
	PlainComments []string                  // 去除注解后的注释
}

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "DBG"
	LogLevelWarn  LogLevel = "WRN"
	LogLevelError LogLevel = "ERR"
	LogLevelFatal LogLevel = "FTL"
)

type Page added in v0.0.8

type Page struct {
	Start int64
	End   int64
}

func NewPages added in v0.0.8

func NewPages(total, pageSize int64) []Page

NewPages 获取带有起始值的页面的数组 @return 返回一个Page数组

type Pagination added in v0.0.8

type Pagination struct {
	Page     uint64 // 第几页
	PageSize uint64 // 每页几项
	Offset   uint64 // 偏移起始值
}

func NewPagination added in v0.0.8

func NewPagination(page, pageSize int64) Pagination

NewPagination 获取分页对象

func (Pagination) GetLimitClause added in v0.0.8

func (p Pagination) GetLimitClause() string

GetLimitClause 获取limit sql子句

type Reflector

type Reflector interface {
	GetFuncName(fn any) string                                     //从函数实例获取函数名
	GetStructName(obj any) string                                  // 从实例获取结构名
	GetVarName(v any) string                                       // 获取变量名
	StructSet(obj any, nilField any, val any) error                // 给结构体设置field类型的值
	MatchReceiverMethods(receiver any, matchFn any) map[string]any // 匹配receiver的所有methods中与matchFn签名参数类似的方法
	GetFuncSignature(fn any) string                                // 获取函数签名信息
	InspectValue(v any) *ValueMeta                                 // 检索Value的信息
	FuncEqual(fn1, fn2 any) bool                                   // 函数是否相等
}

func Reflect

func Reflect() Reflector

type ValueItem

type ValueItem struct {
	Name  string
	Kind  string
	Value any
}

type ValueMeta

type ValueMeta struct {
	Name      string
	IsPointer bool
	Kind      string
	Items     []ValueItem
}

Directories

Path Synopsis
Package parallel 实现了可优雅关闭退出所有的actors Group
Package parallel 实现了可优雅关闭退出所有的actors Group

Jump to

Keyboard shortcuts

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