base

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MulanPSL-2.0 Imports: 10 Imported by: 5

README

base

介绍
  • 基本数据类型常用方法封装

Documentation

Index

Constants

View Source
const (
	DayInt                       = 24 * 3600
	DayDur                       = 24 * time.Hour
	StartTimeSuffix              = " 00:00:00"
	EndTimeSuffix                = " 23:59:59"
	GetDateBetweenForDate  int32 = 1 // 按日处理
	GetDateBetweenForMonth int32 = 2 // 按月处理
	GetDateBetweenForYear  int32 = 3 // 按年处理
)
View Source
const (
	// 时间格式
	YearFmt int8 = 1 << iota
	MonthFmt
	DayFmt
	HourFmt
	MinFmt
	SecFmt
	MilliFmt // 毫秒

	DateFmtFlag          = YearFmt | MonthFmt | DayFmt
	DateTimeFmtFlag      = DateFmtFlag | HourFmt | MinFmt | SecFmt
	MilliDateTimeFmtFlag = DateFmtFlag | HourFmt | MinFmt | SecFmt | MilliFmt
)
View Source
const (
	KCRandKindNum   = 0 // 纯数字
	KCRandKindLower = 1 // 小写字母
	KCRandKindUpper = 2 // 大写字母
	KCRandKindAll   = 3 // 数字、大小写字母
)

用于获取随机字符串

Variables

View Source
var (
	DateFmt     = GetTimeFmt(DateFmtFlag)     // 2006-01-02
	DatetimeFmt = GetTimeFmt(DateTimeFmtFlag) // 2006-01-02 15:04:05
)

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 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 Escape added in v1.3.1

func Escape(src string) string

Escape 转义字符串

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 GetJson2Dump added in v1.2.6

func GetJson2Dump(data interface{}) string

GetJson2Dump 获取待打印的内容

func GetJsonPrintStr

func GetJsonPrintStr(v interface{}) string

Deprecated GetJsonPrintStr 获取打印 json 串, 推荐使用: GetJson2Dump

func GetPageSliceIndex

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

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

func GetPlaceholderStrForNum

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

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

func GetShortStrForRand

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

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

func GetTargeMonthDur

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

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

func GetTargetDateDur

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

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

func GetTimeFmt added in v1.2.6

func GetTimeFmt(fmtType int8, splits ...string) string

GetTimeFmt 获取时间格式化 splits 为分隔符 splits[0] 为 [年月日] 的分割符, 默认为 "-" splits[1] 为 [年月日] 和 [时分秒] 的分割符, 默认为 " " splits[2] 为 [时分秒] 的分割符, 默认为 ":" splits[3] 为 后缀 的分割符, 默认为 "", 如: xxxx-xx-xxTxx:xx:xxZ

func GetWeekInfoForTime

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

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

func InArraySlow added in v1.3.2

func InArraySlow(target interface{}, ins ...interface{}) bool

InArraySlow 判断 target 是否在 ins

func InInt32Array

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

InInt32Array 在 int32 数组

func InString added in v1.1.2

func InString(target string, ins ...string) bool

InString 目标是否在这些内容中

func InUint8Array

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

InUint8Array 在 uint8 数组

func IsExported

func IsExported(fieldName string) bool

IsExported 是可导出

func MarshalUnEscape added in v1.3.2

func MarshalUnEscape(src interface{}) ([]byte, error)

MarshalUnEscape json marshal 不专义

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 Str added in v1.3.1

func Str(src interface{}) string

Str 将内容转为 string

func Str2Int added in v1.3.2

func Str2Int(str string) int

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 将时间戳转为时间字符串

func ToString

func ToString(src interface{}, jsonEscapeHTML ...bool) string

ToString 将内容转为 string, 性能是优于 fmt.Sprintf

Types

type SortMap added in v1.3.1

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

SortMap 用于排序的 map

func NewSortMap added in v1.3.1

func NewSortMap() *SortMap

func (*SortMap) Add added in v1.3.1

func (s *SortMap) Add(key string, value interface{}) *SortMap

func (*SortMap) Delete added in v1.3.1

func (s *SortMap) Delete(key string) *SortMap

func (*SortMap) Get added in v1.3.1

func (s *SortMap) Get(key string) (interface{}, bool)

func (*SortMap) Range added in v1.3.1

func (s *SortMap) Range(f func(key string, value interface{}) error) error

func (*SortMap) String added in v1.3.1

func (s *SortMap) String() string

Jump to

Keyboard shortcuts

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