util

package
Version: v0.0.0-...-c92c86f Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlmostEqual

func AlmostEqual(a, b float64) bool

AlmostEqual returns true is abs(a - b) < 1e-6

func ChinaNow

func ChinaNow() (time.Time, error)

ChinaNow 获取中国时间

func ChinaToday

func ChinaToday() (time.Time, error)

ChinaToday 获取中国时间当天的起始时间

func ChinaYesterday

func ChinaYesterday() (time.Time, error)

ChinaYesterday 获取中国时间昨天的起始时间

func ContainsAny

func ContainsAny(targets []string, checkArr []string) bool

ContainsAny 判断该字符串数据是否包含其中任意一个字符串

func CutRune

func CutRune(str string, max int) string

CutRune 按rune截断字符串

func FormatTime

func FormatTime(t time.Time) string

FormatTime 格式化时间为字符串RFC3339

func GenXID

func GenXID() string

GenXID 生成xid

func GetAccount

func GetAccount(ctx context.Context) string

GetAccount gets account from context

func GetDeviceID

func GetDeviceID(ctx context.Context) string

GetDeviceID gets device is from context

func GetFirstLetter

func GetFirstLetter(str string) string

GetFirstLetter 获取字符串首字母

func GetMockTime

func GetMockTime() string

GetMockTime 获取mock的时间

func GetSessionID

func GetSessionID(c *elton.Context) string

GetSessionID 获取session id

func GetStack

func GetStack(max int) []string

GetStack 获取调用信息

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID gets trace id from context

func GetTrackID

func GetTrackID(c *elton.Context) string

GetTrackID 获取track id

func IsBetween

func IsBetween(begin, end time.Time) bool

IsBetween 判断当前时间是否在开始与结束时间之间

func IsDevelopment

func IsDevelopment() bool

IsDevelopment 判断是否开发环境

func IsProduction

func IsProduction() bool

IsProduction 判断是否生产环境

func IsTest

func IsTest() bool

IsTest 判断是否测试环境

func MapAnyToURLValues

func MapAnyToURLValues(m map[string]any) url.Values

MapAnyToURLValues convert map[string]any to url values

func MapToURLValues

func MapToURLValues(m map[string]string) url.Values

MapToURLValues convert map[string]string to url values

func NewTimeWithRandomNS

func NewTimeWithRandomNS(timestamp int64) time.Time

NewTimeWithRandomNS 根据timestamp并添加随机的ns生成时间

func Now

func Now() time.Time

Now 获取当前时间(测试环境允许使用mock的时间)

func NowString

func NowString() string

NowString 获取当前时间字符串RFC3339

func ParseTime

func ParseTime(str string) (time.Time, error)

ParseTime 字符串转换为时间,字符串为RFC3339格式

func RandomDigit

func RandomDigit(n int) string

RandomDigit 创建指定长度的数字字符串

func RandomString

func RandomString(n int) string

RandomString 创建指定长度的字符串

func SetAccount

func SetAccount(ctx context.Context, account string) context.Context

SetAccount sets account to context

func SetDeviceID

func SetDeviceID(ctx context.Context, deviceID string) context.Context

SetDeviceID sets device id to context

func SetMockTime

func SetMockTime(v string)

SetMockTime 设置mock的时间

func SetTraceID

func SetTraceID(ctx context.Context, traceID string) context.Context

SetTraceID sets trace id to context

func Sha256

func Sha256(str string) string

Sha256 对字符串做sha256后返回base64字符串

func ToFixed

func ToFixed(value float64, precision int) string

ToFixed formats float64 to string

func URLValuesToMap

func URLValuesToMap(values url.Values) map[string]string

URLValuesToMap convert url values to map[string]string

func UTCNow

func UTCNow() time.Time

UTCNow 获取UTC的时间

func UTCNowString

func UTCNowString() string

UTCNowString 获取UTC时间字符串RFC3339

Types

This section is empty.

Jump to

Keyboard shortcuts

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