tools

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	AlgMd5    = 1
	AlgSha1   = 2
	AlgSha256 = 3
)
View Source
const (
	BoxSizeRateMin           float32 = 0.1
	ImageQueryBoxSizeRateMin float32 = 0.1
)
View Source
const (
	SignatureAlgorithmMD5        = "MD5"
	SignatureAlgorithmHMACSHA256 = "HMACSHA256"
)
View Source
const (
	DatetimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var Reader io.Reader
View Source
var UUIDRegexp = regexp.MustCompile(fmt.Sprintf("^[a-f0-9]{8}%c([a-f0-9]{4}%c){3}[a-f0-9]{12}$", uuidDash, uuidDash))

Functions

func CheckSum

func CheckSum(data []byte) uint32

CheckSum compute checksum of input data.

func ComputeAge added in v0.0.3

func ComputeAge(birthStr string, baseDate *time.Time) (age int)

func Copy added in v0.0.3

func Copy(src any, dest any) error

func CreateDate added in v0.0.4

func CreateDate(year, month, day int) *time.Time

func CreateDir

func CreateDir(path string, mode os.FileMode) error

CreateDir create dir.

func CreateDirIfNotExists

func CreateDirIfNotExists(path string, mode os.FileMode) error

CreateDirIfNotExists create dir if not exists.

func CreateTime added in v0.0.4

func CreateTime(year, month, day, hour, min, sec int) *time.Time

func CurrentDataCompactStr added in v0.0.2

func CurrentDataCompactStr() string

CurrentDataCompactStr return current date in format yyyyMMdd

func CurrentDateInSeconds

func CurrentDateInSeconds() int64

CurrentDateInSeconds return the seconds representation of the current date in local

func CurrentDateStr added in v0.0.2

func CurrentDateStr() string

CurrentDateStr return current date in format yyyy-MM-dd

func CurrentDateTimeStr added in v0.0.2

func CurrentDateTimeStr() string

CurrentDateTimeStr return current datetime in format yyyy-MM-dd HH:mm:ss

func CurrentTimeCompactStr added in v0.0.2

func CurrentTimeCompactStr() string

CurrentTimeCompactStr return current time in format HHmmss

func DaysAfter added in v0.0.4

func DaysAfter(base *time.Time, n int) *time.Time

func DaysAgo added in v0.0.4

func DaysAgo(base *time.Time, n int) *time.Time

func DaysBefore

func DaysBefore(days int) int64

DaysBefore return the seconds representation of the start of days before now in local

func Decode

func Decode(jsonStr string, v any)

Decode deserialize

func DecodeBytes

func DecodeBytes(jsonBytes []byte, v any) error

DecodeBytes deserialize

func DecodeFile

func DecodeFile(file string, v any) error

DecodeFile deserialize file content.

func DecodeJson5 added in v0.0.3

func DecodeJson5(filePath string, output any) error

func DeleteFile

func DeleteFile(path string) bool

DeleteFile remove file return false if failed.

func DeleteFiles

func DeleteFiles(path string) bool

DeleteFiles remove dirs and files in path return false if failed.

func DoGet added in v0.0.3

func DoGet(rawUrl, uri, token string, params *url.Values, result any) (code int, err error)

func DoPost added in v0.0.3

func DoPost(rawUrl, uri string, token string, params *url.Values, body any, result any) (code int, err error)

func DoRequest added in v0.0.3

func DoRequest(method, rawUrl, uri string, params *url.Values, header *http.Header, body io.Reader) (resp *http.Response, err error)

func Encode

func Encode(v any) string

Encode serialize

func EncodeBytes

func EncodeBytes(v any) []byte

EncodeBytes serialize

func EncodeObj

func EncodeObj(v any, file string) error

EncodeObj serialize object to file.

func ExportToUTCMills added in v0.0.4

func ExportToUTCMills(localMillSec int64) (millSec int64)

func ExtractCerInfo added in v0.0.3

func ExtractCerInfo(cerNo string) (province, city, district, birthStr string, birth int64, age int, isMale int8)

ExtractCerInfo isMale 1:女性 2:男性

func ExtractDate added in v0.0.4

func ExtractDate(value *time.Time) *time.Time

func FileCheckSum

func FileCheckSum(file string) (r uint32)

FileCheckSum compute checksum of the input file.

func FileExists

func FileExists(path string) bool

FileExists return true if file exists.

func Float32Round

func Float32Round(f float32, pOffset int64) float32

func FormatMilliSecondsToDateStr added in v0.0.4

func FormatMilliSecondsToDateStr(millSec int64) string

func FormatMilliSecondsToStr added in v0.0.4

func FormatMilliSecondsToStr(millSec int64, fmt string) string

func FormatMilliSecondsToTimeStr added in v0.0.4

func FormatMilliSecondsToTimeStr(millSec int64) string

func GeoDistance added in v0.0.4

func GeoDistance(lng1, lat1, lng2, lat2 float64) float64

func GetCurrentDate added in v0.0.4

func GetCurrentDate() *time.Time

func GetCurrentMillSeconds added in v0.0.4

func GetCurrentMillSeconds() int64

func GetCurrentSeconds added in v0.0.4

func GetCurrentSeconds() int64

func GetDateCompactString added in v0.0.4

func GetDateCompactString(time *time.Time) string

func GetLocalTime added in v0.0.4

func GetLocalTime() *time.Time

func GetMilliSeconds added in v0.0.4

func GetMilliSeconds(t *time.Time) (millSec int64)

func GetTimeInSeconds

func GetTimeInSeconds(timeStr string) int64

GetTimeInSeconds return the seconds representation of the timeString

timeStr in format hhhmmmsss ,e.g. 23h10m34s ,otherwise return -1

func GetTimeString added in v0.0.4

func GetTimeString(format string, time *time.Time) string

func GetTimeWithMilliSeconds added in v0.0.4

func GetTimeWithMilliSeconds(millSec int64) *time.Time

func GetTodayCompactString added in v0.0.4

func GetTodayCompactString() string

func GetToken added in v0.0.3

func GetToken(method, rawUrl, uri, user, password string) (token string, err error)

func GetWeekEndDate added in v0.0.4

func GetWeekEndDate(now *time.Time) *time.Time

func GetWeekStartDate added in v0.0.4

func GetWeekStartDate(now *time.Time) *time.Time

func HashUUID

func HashUUID(bs []byte) string

HashUUID generate hash uuid of the input data.

func ImagEmpty

func ImagEmpty(a []uint8) float32

func ImageColorId

func ImageColorId(im image.Image) uint64

func ImageHashContentRate

func ImageHashContentRate(a uint64) float32

func ImageHashDiff

func ImageHashDiff(a, b uint64) float32

func ImageHashId

func ImageHashId(im image.Image, bs []byte) (image.Image, image.Image, uint64, error)

func ImageHashNull

func ImageHashNull(a uint64) uint8

func ImageMaskAllow

func ImageMaskAllow(masks [][]float32, x, y int, w, h int) bool

func ImagePixGray

func ImagePixGray(im image.Image, x, y int) uint8

func ImageSimilarity

func ImageSimilarity(a, b []uint8) float32

func ImageTag

func ImageTag(m image.Image, tagSpace int) []uint8

func ImgBytesDecode

func ImgBytesDecode(bs []byte) (image.Image, error)

func ImgShmBytes

func ImgShmBytes(file string) ([]byte, error)

func ImportFromUTCMills added in v0.0.4

func ImportFromUTCMills(utcMillSec int64) (localMillSec int64)

func IndentJson added in v0.0.4

func IndentJson(value any, prefix, indent string) string

func IsType added in v0.0.3

func IsType[T any](a any) bool

func IsValidCardNo18 added in v0.0.3

func IsValidCardNo18(CardNo18 *[]byte) bool

func IsValidUUID

func IsValidUUID(UUID string) bool

IsValidUUID check if UUID is in valid format.

func LocalIP added in v0.0.3

func LocalIP() (ip string)

func MaskCerNo added in v0.0.5

func MaskCerNo(raw string) (result string)

func MaskPhone added in v0.0.5

func MaskPhone(raw string) (result string)

func MonthDays added in v0.0.4

func MonthDays(t *time.Time) (days int)

func MonthsAgo added in v0.0.4

func MonthsAgo(base *time.Time, n int) *time.Time

func NumberToFixedPrice added in v0.0.4

func NumberToFixedPrice(number int) string

func NumberToShortPrice added in v0.0.4

func NumberToShortPrice(number int) (price string)

func ParseMilliSecondsFromStr added in v0.0.4

func ParseMilliSecondsFromStr(timeStr string) (millSec int64)

func ParseResponse added in v0.0.3

func ParseResponse(resp *http.Response, result any) (code int, err error)

func ParseTimeFromStr added in v0.0.4

func ParseTimeFromStr(timeStr string) (*time.Time, error)

func ParseTimeInLocation added in v0.0.4

func ParseTimeInLocation(timeStr, timeFmt string) (*time.Time, error)

func PriceToNumber added in v0.0.4

func PriceToNumber(price string) int

func RandUUID

func RandUUID() string

RandUUID generate random hash uuid.

func RandomAlphaNum added in v0.0.3

func RandomAlphaNum(length int) string

func RandomNumChar added in v0.0.3

func RandomNumChar(length int) string

func ReadFile added in v0.0.3

func ReadFile(filename string, preRead int) (<-chan string, context.CancelFunc, error)

func Sign added in v0.0.3

func Sign(raw []byte, algo string) (signature []byte)

func SplitSeconds

func SplitSeconds(seconds int64) (int64, int64)

SplitSeconds return unix timestamp in seconds with two part:begin of a day and the offset

func SymDiff added in v0.0.4

func SymDiff[T comparable](a, b []T) (da, db []T)

func TimeRingFromDaysAgo

func TimeRingFromDaysAgo(days int) *ring.Ring

TimeRingFromDaysAgo return time ring from days ago util next day.

func ToAny added in v0.0.3

func ToAny[T any](a any) T

func ToAnyE added in v0.0.3

func ToAnyE[T any](a any) (T, bool)

func ToAnySlice added in v0.0.4

func ToAnySlice[T, S any](a []S) []T

func ToAnySliceE added in v0.0.4

func ToAnySliceE[T, S any](a []S) (results []T, ok bool)

func ToNumber added in v0.0.4

func ToNumber(numStr string) int

func TransJson added in v0.0.4

func TransJson(json *types.Json, result any)

func TransMinuteToSec added in v0.0.4

func TransMinuteToSec(timeStr string) (sec int)

func TransSecondStrToSec added in v0.0.4

func TransSecondStrToSec(timeStr string) (sec int)

func TransTimeFormat

func TransTimeFormat(timeString string) string

TransTimeFormat Trans time format from hh:mm:ss to hhhmmmsss.If timeString format invalid return itself

eg. 23:10:34 => 23h10m34s

func TransTimeSec added in v0.0.4

func TransTimeSec(timeStr string) (sec int)

func Trunc added in v0.0.4

func Trunc(value float64, precision int) float64

func ValidJson added in v0.0.4

func ValidJson(v *types.Json) bool

func ValidNumberList added in v0.0.4

func ValidNumberList(v *types.Json) bool

func ValidStringList added in v0.0.4

func ValidStringList(v *types.Json) bool

Types

type ID added in v0.0.4

type ID int64

func GenerateID added in v0.0.4

func GenerateID() ID

func (ID) Base36 added in v0.0.4

func (i ID) Base36() string

func (ID) Int64 added in v0.0.4

func (i ID) Int64() int64

func (ID) String added in v0.0.4

func (i ID) String() string

Jump to

Keyboard shortcuts

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