utils

package
v0.0.0-...-ca21e7b Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormat 标准时间格式
	TimeFormat = "2006-01-02 15:04:05"
	// DateFormat 标准日期格式
	DateFormat = "2006-01-02"
	// TimeFormatWithZone 带时区的时间格式
	TimeFormatWithZone = "2006-01-02 15:04:05 -0700"
	// TimeFormatWithMilli 带毫秒的时间格式
	TimeFormatWithMilli = "2006-01-02 15:04:05.000"
)

Variables

This section is empty.

Functions

func DecryptString

func DecryptString(ciphertext string, key []byte) (string, error)

DecryptString 解密字符串

func EncryptString

func EncryptString(text string, key []byte) (string, error)

EncryptString 加密字符串

func FormatDate

func FormatDate(t time.Time) string

FormatDate 格式化日期为字符串

func FormatTime

func FormatTime(t time.Time) string

FormatTime 格式化时间为字符串

func FormatTimeWithMilli

func FormatTimeWithMilli(t time.Time) string

FormatTimeWithMilli 格式化时间为带毫秒的字符串

func FormatTimeWithZone

func FormatTimeWithZone(t time.Time) string

FormatTimeWithZone 格式化时间为带时区的字符串

func GenerateToken

func GenerateToken(length int) (string, error)

GenerateToken 生成随机令牌

func GetEndOfDay

func GetEndOfDay(t time.Time) time.Time

GetEndOfDay 获取一天的结束时间

func GetEndOfMonth

func GetEndOfMonth(t time.Time) time.Time

GetEndOfMonth 获取一个月的结束时间

func GetEndOfWeek

func GetEndOfWeek(t time.Time) time.Time

GetEndOfWeek 获取一周的结束时间

func GetStartOfDay

func GetStartOfDay(t time.Time) time.Time

GetStartOfDay 获取一天的开始时间

func GetStartOfMonth

func GetStartOfMonth(t time.Time) time.Time

GetStartOfMonth 获取一个月的开始时间

func GetStartOfWeek

func GetStartOfWeek(t time.Time) time.Time

GetStartOfWeek 获取一周的开始时间

func HashPassword

func HashPassword(password string) (string, error)

HashPassword 使用 bcrypt 对密码进行哈希

func IsThisMonth

func IsThisMonth(t time.Time) bool

IsThisMonth 判断是否是本月

func IsThisWeek

func IsThisWeek(t time.Time) bool

IsThisWeek 判断是否是本周

func IsToday

func IsToday(t time.Time) bool

IsToday 判断是否是今天

func MakeAllFieldsRequired

func MakeAllFieldsRequired(schema *openapi3.Schema)

递归设置所有嵌套Schema的additionalProperties为false并使所有字段required

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate 解析日期字符串

func ParseTime

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

ParseTime 解析时间字符串

func ParseTimeWithMilli

func ParseTimeWithMilli(s string) (time.Time, error)

ParseTimeWithMilli 解析带毫秒的时间字符串

func ParseTimeWithZone

func ParseTimeWithZone(s string) (time.Time, error)

ParseTimeWithZone 解析带时区的时间字符串

func Ternary

func Ternary[T any](condition bool, trueValue, falseValue T) T

Ternary 三元表达式工具函数 condition: 条件表达式 trueValue: 条件为真时的返回值 falseValue: 条件为假时的返回值 返回: 根据条件返回对应的值

func VerifyPassword

func VerifyPassword(hashedPassword, password string) bool

VerifyPassword 验证密码是否匹配

Types

type ParserState

type ParserState int

ParserState JSON 解析器的状态类型

const (
	VALUE ParserState = iota
	KEY_OR_END
	KEY
	COLON
	COMMA
	VALUE_OR_END
	NUMBER
	TRUE1
	TRUE2
	TRUE3
	FALSE1
	FALSE2
	FALSE3
	FALSE4
	NULL1
	NULL2
	NULL3
)

type PathMatcherCallback

type PathMatcherCallback func(value interface{}, path []interface{})

PathMatcherCallback 路径匹配器的回调函数类型

type PathPattern

type PathPattern struct {
	Tokens   []interface{} // 解析后的标记数组
	Original string        // 原始模式字符串
	Callback PathMatcherCallback
}

PathPattern 路径匹配模式类型

type SimplePathMatcher

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

SimplePathMatcher 简化版 JSON 路径匹配系统

func NewSimplePathMatcher

func NewSimplePathMatcher() *SimplePathMatcher

NewSimplePathMatcher 创建新的路径匹配器

func (*SimplePathMatcher) CheckPatterns

func (m *SimplePathMatcher) CheckPatterns(path []interface{}, value interface{})

CheckPatterns 检查当前路径是否匹配任何注册的模式

func (*SimplePathMatcher) On

On 注册一个路径模式和对应的回调函数

type StreamingJsonParser

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

StreamingJsonParser 真实的流式 JSON 解析器

func NewStreamingJsonParser

func NewStreamingJsonParser(matcher *SimplePathMatcher, realtime bool, incremental bool) *StreamingJsonParser

NewStreamingJsonParser 创建新的流式JSON解析器 realtime: 控制是否实时返回解析结果 incremental: 控制是返回增量内容(true)还是累积内容(false)

func (*StreamingJsonParser) End

func (p *StreamingJsonParser) End() error

End 结束解析

func (*StreamingJsonParser) GetResult

func (p *StreamingJsonParser) GetResult() interface{}

GetResult 获取解析结果

func (*StreamingJsonParser) Reset

func (p *StreamingJsonParser) Reset()

Reset 重置解析器状态

func (*StreamingJsonParser) Write

func (p *StreamingJsonParser) Write(chunk string) error

Write 逐字符处理输入流

Jump to

Keyboard shortcuts

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