gotools

package module
v0.0.0-...-0b965da Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MulanPSL-2.0 Imports: 14 Imported by: 0

README

go-tools

介绍
  1. 常用方法的封装

Documentation

Index

Constants

View Source
const (
	DayInt                 int           = 24 * 3600
	DayDur                 time.Duration = 24 * time.Hour
	DateFmt                string        = "2006-01-02"
	DatetimeFmt            string        = "2006-01-02 15:04:05"
	StartTimeSuffix        string        = " 00:00:00"
	EndTimeSuffix          string        = " 23:59:59"
	GetDateBetweenForDate  int32         = 1 // 按日处理
	GetDateBetweenForMonth int32         = 2 // 按月处理
	GetDateBetweenForYear  int32         = 3 // 按年处理
)
View Source
const (
	KCRandKindNum   = 0 // 纯数字
	KCRandKindLower = 1 // 小写字母
	KCRandKindUpper = 2 // 大写字母
	KCRandKindAll   = 3 // 数字、大小写字母
)

用于获取随机字符串

Variables

This section is empty.

Functions

func AddDate

func AddDate(date string, add time.Duration, format ...string) time.Time

AddDate 增加时间

func AddDateForInt

func AddDateForInt(date string, years, months, days int, format ...string) time.Time

AddDateForInt 增加时间

func CopyFile

func CopyFile(src, dst string, isFirstDel ...bool) (err error)

CopyFile 复制文件

func Datetime2TimeObj

func Datetime2TimeObj(target string, format ...string) time.Time

Datetime2TimeObj

func Datetime2Timestamp

func Datetime2Timestamp(date string, format ...string) int64

Datetime2Timestamp 将时间字符串转为时间戳

func DatetimeBetween

func DatetimeBetween(target, startDatetime, endDatetime string) bool

DatetimeBetween 判断目标时间是否在开始时间和结束时间之间

func DatetimeIsExpire

func DatetimeIsExpire(date string, expire ...time.Duration) bool

DatetimeIsExpire 判断输入时间是否过期

func DistinctIds

func DistinctIds(ids []string) []string

DistinctIds 去重

func DistinctIdsStr

func DistinctIdsStr(s string, split string) string

DistinctIdsStr 将输入拼接 id 参数按照指定字符进行去重, 如: DistinctIdsStr("12345,123,20,123,20,15", ",") => 12345,123,20,15

func DistinctInt32Ids

func DistinctInt32Ids(ids []int32) (res []int32)

DistinctInt32Ids 去重

func FormatBusinessDate

func FormatBusinessDate(date string) (finalStr string)

FormatBusinessDate 将输入的时间转为业务需要时间, 规则如下: 1. 1分钟内发布的: 刚刚 2. 1小时内发布的: X分钟前 3. 超过1小时, 仍在当天: xx:xx 4. 跨天,但少于24小时: 昨天 xx:xx 5. 跨天, 超过24小时: xxxx-xx-xx xx:xx

func GetAgeForBirthday

func GetAgeForBirthday(birthday string, format ...string) (age int)

GetAgeForBirthday 根据出生日期获取年龄

func GetDateBetween

func GetDateBetween(startDate, endDate string, args ...int32) []string

GetDateBetween 获取开始时间和结束时间中的日期 args[0] 为操作类型, 默认为 GetDateBetweenForDate args[1] 为了防止死循环设置的最大循环次数, 默认 365(1年)

func GetInputStr2ShortStr

func GetInputStr2ShortStr(input string, size ...int) string

size 建议不要传入, 这样会提高重复率

func GetJsonPrintStr

func GetJsonPrintStr(v interface{}) string

GetJsonPrintStr 获取打印 json 串

func GetPapeSliceIndex

func GetPapeSliceIndex(page, size int32, l int) (startIndex, endIndex int32)

GetPapeSliceIndex 根据page, size对切片进行分页, l 为目标切片的长度

func GetPlaceholderStrForNum

func GetPlaceholderStrForNum(size int, num int64, placeholder ...byte) string

GetPlaceholderStrForNum 获取指定位数占位符的字符串

func GetProjectDir

func GetProjectDir(projectName string) string

GetProjectDir 获取项目路径

func GetShortStrForRand

func GetShortStrForRand(size int, kind ...int) string

随机字符串, 默认按照: 数字、大小写字母进行处理

func GetSysPathSplitSymbol

func GetSysPathSplitSymbol() (splitSymbol string)

GetSysPathSplitSymbol 根据系统获取路径分隔符

func GetTargeMonthDur

func GetTargeMonthDur(target time.Time) (startDatetime, endDatetime string)

GetCurMonthDur 获取指定月的开始和结束时间

func GetTargetDateDur

func GetTargetDateDur(target time.Time) (startDatetime, endDatetime string)

GetAddDateDur 获取指定时间的当天开始时间和结束时间

func InInt32Array

func InInt32Array(target int32, in ...int32) bool

InInt32Array 在 int32 数组

func InUint8Array

func InUint8Array(target uint8, in ...uint8) bool

InUint8Array 在 uint8 数组

func IsExported

func IsExported(fieldName string) bool

IsExported 是可导出

func MurmurHash2Uint64

func MurmurHash2Uint64(data []byte) (hash uint64)

通过 Murmur 获取 hash uint64 的哈希值

func NewCjLogger

func NewCjLogger() *defaultLogger

func ParseFileFormat

func ParseFileFormat(fileName string) string

ParseFileFormat 解析文件格式

func PriceNum2Str

func PriceNum2Str(value int32) string

PriceNum2Str 价格处理, 将价格: 元=>分

func PriceStr2Str

func PriceStr2Str(value string) (ans string)

PriceStr2Str 价格处理, 将价格: 元=>分

func RemoveTypePtr

func RemoveTypePtr(t reflect.Type) reflect.Type

RemoveTypePtr 移除多指针

func RemoveValuePtr

func RemoveValuePtr(t reflect.Value) reflect.Value

RemoveValuePtr 移除多指针

func Second2Hour

func Second2Hour(s int) (hour, min, sec int)

Second2Hour 秒转分

func SetLogger

func SetLogger(logger Logger)

SetLogger 设置 logger

func SubDate

func SubDate(date, sub string, format ...string) time.Duration

SubDate 获取两个时间的差值

func SubNow2Year

func SubNow2Year(year string) string

SubNow2Year 目标年与现在的差

func Timestamp2Datetime

func Timestamp2Datetime(timestamp int64, format ...string) string

Timestamp2Datetime 将时间戳转为时间字符串

Types

type Logger

type Logger interface {
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Warning(v ...interface{})
	Warningf(format string, v ...interface{})
	Panic(v ...interface{})
	Panicf(format string, v ...interface{})
}

Logger

type WeekInfo

type WeekInfo struct {
	StartTimeObj time.Time         // 本周的最开始对象
	EndTimeObj   time.Time         // 本周的结束对象
	StartDate    string            // 本周开始日期
	EndDate      string            // 本周结束日期
	Dates        []string          // 日期
	Date2WeekMap map[string]string // 保存的日期对应的星期几, map[2021-09-01]星期一
}

func GetWeekInfoForTime

func GetWeekInfoForTime(dateFormat string, t ...time.Time) *WeekInfo

根据输入的 time 来获取本周的日期和星期几, 如果没有输入默认按当前时间处理

Jump to

Keyboard shortcuts

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