Documentation
¶
Index ¶
- func CleanInvalidUTF8(s string) string
- func Deduplicate[T any, K comparable](keyFunc func(T) K, items ...T) []T
- func DeduplicateWithScore[T ScoreComparable, K comparable](keyFunc func(T) K, items ...T) []T
- func ExtractBalancedJSON(s string) string
- func GetAttrs[A, B any](extract func(A) B, attrs ...A) []B
- func IsDeadlockError(err error) bool
- func ParseLLMJsonResponse(content string, target interface{}) error
- func PipelineError(ctx context.Context, stage, action string, fields map[string]interface{})
- func PipelineInfo(ctx context.Context, stage, action string, fields map[string]interface{})
- func PipelineLog(stage, action string, fields map[string]interface{}) string
- func PipelineWarn(ctx context.Context, stage, action string, fields map[string]interface{})
- func RedisTLSConfig() *tls.Config
- func StringSliceJoin(slice []string) string
- func ToInterfaceSlice[T any](slice []T) []interface{}
- func TruncateForLog(content string) string
- func WithDeadlockRetry(ctx context.Context, fn func() error) error
- type ScoreComparable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanInvalidUTF8 ¶
CleanInvalidUTF8 移除字符串中的非法 UTF-8 字符和 \x00
func Deduplicate ¶
func Deduplicate[T any, K comparable](keyFunc func(T) K, items ...T) []T
Deduplicate removes duplicates from a slice based on a key function T: the type of elements in the slice K: the type of key used for deduplication
func DeduplicateWithScore ¶
func DeduplicateWithScore[T ScoreComparable, K comparable](keyFunc func(T) K, items ...T) []T
DeduplicateWithScore removes duplicates from a slice based on a key function, keeping the item with the highest score for each key, then sorts by score descending T: the type of elements in the slice (must implement ScoreComparable) K: the type of key used for deduplication
func ExtractBalancedJSON ¶
ExtractBalancedJSON returns the first balanced JSON object or array embedded in s, or an empty string when there is none. Whichever bracket type opens first wins, and quoted strings are skipped so braces inside string literals do not unbalance the scan. The result is not validated as JSON; callers must still unmarshal it.
func IsDeadlockError ¶
IsDeadlockError checks whether err is a MySQL deadlock (Error 1213).
func ParseLLMJsonResponse ¶
func PipelineError ¶
PipelineError logs pipeline error level entries.
func PipelineInfo ¶
PipelineInfo logs pipeline info level entries.
func PipelineLog ¶
PipelineLog builds a structured pipeline log string.
func PipelineWarn ¶
PipelineWarn logs pipeline warning level entries.
func RedisTLSConfig ¶
RedisTLSConfig builds a *tls.Config for Redis connections from environment variables. It returns nil when TLS is disabled, so the result can be assigned directly to redis.Options.TLSConfig or asynq.RedisClientOpt.TLSConfig (a nil value keeps the existing plaintext behavior).
Environment variables:
REDIS_USE_TLS Enable TLS when "true" (default: disabled).
REDIS_TLS_SERVER_NAME Optional server name for certificate
verification and SNI (useful when the address
is an IP rather than a hostname).
REDIS_TLS_INSECURE_SKIP_VERIFY Skip server certificate verification when
"true". INSECURE — intended for development or
self-signed setups only; do not use in production.
The server certificate is verified by default; verification is only relaxed when REDIS_TLS_INSECURE_SKIP_VERIFY is explicitly set to "true".
func StringSliceJoin ¶
[]string -> string, " join, space separated
func ToInterfaceSlice ¶
func ToInterfaceSlice[T any](slice []T) []interface{}
ToInterfaceSlice converts a slice of strings to a slice of empty interfaces.
func TruncateForLog ¶
func WithDeadlockRetry ¶
WithDeadlockRetry retries fn when MySQL returns Error 1213 (deadlock). Retries up to 3 times with exponential backoff (50ms, 100ms, 200ms). Safe for all DB drivers — non-deadlock errors are returned immediately.
Types ¶
type ScoreComparable ¶
type ScoreComparable interface {
GetScore() float64
}
ScoreComparable is an interface for types that have a Score method returning float64