kit

package module
v0.0.0-...-452f74e Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

Go Reference Go

yo-kit

yo 脚手架基础库。

开发

测试:

go test -v -count=1 ./...

安装

go get -u github.com/zhangjie2012/yo-kit@main

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNone                = ""                      // no error 没错
	ErrBadRequest          = "Bad Request"           // bad request 错误的请求(参数错误)
	ErrInternalServerError = "Internal Server Error" // server logic error 服务器内部错误, 服务器自身逻辑问题
	ErrInvalidParams       = "Invalid Params"        // invalid params 参数格式错误
	ErrInvalidPassword     = "Invalid Password"      // invalid password 密码错误
	ErrInvalidVerifyCode   = "Invalid Verify Code"   // invalid verify code 验证码无效
	ErrLoginRequired       = "Login Required"        // need login 需要登录
	ErrNotFound            = "Not Found"             // resource not found 资源不存在
	ErrOutOfRange          = "Out Of Range"          // out of range 越界访问
	ErrPermissionDenied    = "Permission Denied"     // permission denied 权限不足
	ErrTooManyRequests     = "Too Many Requests"     // too many requests 请求过于频繁, 限流
)

Functions

func B2i

func B2i(b bool) int

B2i bool to int

func DayOfWeekCN

func DayOfWeekCN(n int) string

DayOfWeekCN 每天的星期中文描述

func DayOfWeekCN2

func DayOfWeekCN2(n int) string

DayOfWeekCN2 每天的周几中文描述

func DurationString

func DurationString(d time.Duration) string

DurationString 时间区间描述

func EndOfDay

func EndOfDay(t time.Time) time.Time

EndOfDay one day end time

func EndOfMonth

func EndOfMonth(t time.Time) time.Time

EndOfMonth month end datetime

func EndOfWeek

func EndOfWeek(t time.Time) time.Time

EndOfWeek week last day

func EndOfYear

func EndOfYear(t time.Time) time.Time

EndOfYear one year end time

func FormatDayTime

func FormatDayTime(t time.Time, showSec bool) string

FormatDayTime 按照一天不同的时间段转换成友好的中文描述

func GenRSessionID

func GenRSessionID() string

GenRSessionID generate a random session id, most business scene recommand

func GenUSessionID

func GenUSessionID() string

GenSessionID generate a unique session id

func GenUUIDV1

func GenUUIDV1() string

GenUUIDV1 global unique id

func GenUUIDV4

func GenUUIDV4() string

GenUUIDV4 wikipedia said Randomly generated UUIDs have 122 random bits. One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 x 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.

(most business scene recommand)

func GenVerifyCodeAny

func GenVerifyCodeAny(pool string, width int) string

GenVerifyCodeAny generate verify code, get from pool

func GenVerifyCodeCommon

func GenVerifyCodeCommon(width int) string

GenVerifyCodeCommon generate verify code, letter + number

func GenVerifyCodeNumber

func GenVerifyCodeNumber(width int) string

GenVerifyCodeNumber generate verify code, all is number

func GetOutboundIP

func GetOutboundIP() net.IP

GetOutboundIP get IP address code via https://stackoverflow.com/a/37382208/802815

func HidePhonenumSensitive

func HidePhonenumSensitive(s string) string

HidePhonenumSensitive hide phonenum sensitive info 手机号脱敏

func I2b

func I2b(i int) bool

I2b int t bool

func Int64SliceToString

func Int64SliceToString(a []int64, delim string) string

Int64SliceToString a int64 slice to string Ref: https://stackoverflow.com/questions/37532255/one-liner-to-transform-int-into-string

func IntSliceToString

func IntSliceToString(a []int, delim string) string

IntSliceToString a int64 slice to string Ref: https://stackoverflow.com/questions/37532255/one-liner-to-transform-int-into-string

func MobileValidate

func MobileValidate(mm string) bool

func RangeMonth

func RangeMonth(t time.Time) []time.Time

RangeMonth get month every day date

func RangeWeek

func RangeWeek(t time.Time) []time.Time

RangeWeek range week every day date

func RangeYear

func RangeYear(t time.Time) []time.Time

RangeYear range year every day date

func SliceDifference

func SliceDifference(a []string, b []string) []string

SliceDifference 差集

func SliceIntersection

func SliceIntersection(a []string, b []string) []string

SliceIntersection 交集

func SliceUnion

func SliceUnion(a []string, b []string) []string

SliceUnion 并集

func SliceUniq

func SliceUniq(a []string) []string

SliceUniq 去重

func SliceUniqInt

func SliceUniqInt(a []int) []int

func SliceUniqInt64

func SliceUniqInt64(a []int64) []int64

func SortByKeySF64

func SortByKeySF64(m map[string]float64, asc bool) []*datastruct.SF64Pair

SortByKeysSF64 <string, float64> map sort by keys [via]: https://www.geeksforgeeks.org/how-to-sort-golang-map-by-keys-or-values/

func SortByValueSF64

func SortByValueSF64(m map[string]float64, asc bool) []*datastruct.SF64Pair

SortByValueSF64 <string, float64> map sort by values

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay one day start time

func StartOfMonth

func StartOfMonth(t time.Time) time.Time

StartOfMonth month start datetime

func StartOfWeek

func StartOfWeek(t time.Time) time.Time

StartOfWeek week first day

func StartOfYear

func StartOfYear(t time.Time) time.Time

StartOfYear one year start time

func StringSplit

func StringSplit(source string, sep string) []string

StringSplit string split by `sep` the standard library `Split` when `source` is a empty string, will return a `[""]` slice. In fact, most of time, we want return a length equal 0 slice, `[]`

func TraverseTimeRangeByMonth

func TraverseTimeRangeByMonth(start time.Time, end time.Time) (pairs []*datastruct.TimePair)

TraverseTimeRangeByMonth 在 start ~ end 范围内,以月为单位遍历

func TraverseTimeRangeByWeek

func TraverseTimeRangeByWeek(start time.Time, end time.Time) (pairs []*datastruct.TimePair)

TraverseTimeRangeByWeek 在 start ~ end 范围内,以周为单位遍历

func TraverseTimeRangeByYear

func TraverseTimeRangeByYear(start time.Time, end time.Time) (pairs []*datastruct.TimePair)

TraverseTimeRangeByYear 在 start ~ end 范围内,以年为单位遍历

func TruncateString

func TruncateString(str string, length int) string

TruncateString Ref: https://dev.to/takakd/go-safe-truncate-string-9h0

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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