common

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Capitalize 首字母大写

func DefaultConfigPath

func DefaultConfigPath(filename string) string

func DefaultConfigPathWithName

func DefaultConfigPathWithName(name string, filename string) string

func DefaultDBPath

func DefaultDBPath(dsn string) string

func DefaultDBPathWithName

func DefaultDBPathWithName(name string, dsn string) string

func DefaultDownloadPath

func DefaultDownloadPath(filename string) string

func DefaultDownloadPathWithName

func DefaultDownloadPathWithName(name string, filename string) string

func DefaultLogPath

func DefaultLogPath(app string) string

DefaultLogPath 外部调用(推荐使用这个)自动判断操作系统并返回默认日志路径

func DefaultLogPathWithName

func DefaultLogPathWithName(name string, filename string) string

DefaultLogPathWithName 返回日志完整路径:<log_dir>/<filename>,若 filename 为空则自动生成。

func ElapsedTimeSince

func ElapsedTimeSince(beginTime time.Time) string

func Exists added in v1.0.1

func Exists(path string) bool

Exists checks if a file or directory exists

func Filter added in v1.0.1

func Filter[T any](input []T, fn func(T) bool) []T

Filter 过滤函数:返回满足条件的 []T 子集

func Find added in v1.0.1

func Find[T any](input []T, fn func(T) bool) (T, bool)

Find 查找函数:返回首个满足条件的元素及是否找到

func JSONString

func JSONString(data interface{}) string

func Map added in v1.0.1

func Map[T any, R any](input []T, fn func(T) R) []R

Map 映射函数:将 []T 映射为 []R

func PrettyJSONString

func PrettyJSONString(data interface{}) string

func PrettyStruct

func PrettyStruct(data interface{}) (string, error)

func Reduce added in v1.0.1

func Reduce[T any, R any](input []T, initial R, fn func(R, T) R) R

Reduce 累加函数:将 []T 聚合成一个 R 值

func SnakeToCamel added in v1.0.1

func SnakeToCamel(s string) string

func TimeCost

func TimeCost() func()

TimeCost @brief:耗时统计函数

func ToSnakeCase added in v1.0.1

func ToSnakeCase(str string) string

ToSnakeCase converts camelCase to snake_case

func WithTempDir

func WithTempDir(do func(tempDir string) error) error

WithTempDir 创建临时目录,执行用户提供的操作函数,结束后自动删除该目录。

Types

This section is empty.

Jump to

Keyboard shortcuts

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