Documentation
¶
Overview ¶
* @Author: lixu lixu@puchigames.com * @Date: 2025-07-03 16:49:48 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-07-03 16:52:02 * @FilePath: /go-helper/utils/array.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 11:00:00 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:53:12 * @FilePath: /go-helper/utils/config.go * @Description: 配置文件处理工具函数,支持JSON、YAML、ENV等格式的配置文件
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:17:13 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:17:20 * @FilePath: /go-helper/utils/convert.go * @Description: 类型转换工具函数,包含字符串、数字、布尔值等类型之间的相互转换功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:37:05 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:39:33 * @FilePath: /go-helper/utils/crypto.go * @Description: 加密相关工具函数,包含MD5、SHA系列、HMAC、Base64、Hex等加密和编码功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:17:13 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 16:17:54 * @FilePath: /go-helper/utils/file.go * @Description: 文件操作工具函数,包含文件读写、目录操作、文件信息获取等功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:40:44 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-17 10:44:20 * @FilePath: /go-helper/utils/http.go * @Description: HTTP相关工具函数,包含请求、响应、Cookie、Session等处理功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:17:13 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:17:20 * @FilePath: /go-helper/utils/random.go * @Description: 随机数生成工具函数,包含随机整数、随机字符串、随机数组、随机UUID等功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:17:13 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:17:20 * @FilePath: /go-helper/utils/struct.go * @Description: 结构体处理工具函数,包含结构体转换、字段操作、标签处理等功能
* @Author: lixu lixu@puchigames.com * @Date: 2025-07-03 16:43:02 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-07-03 16:48:52 * @FilePath: /go-helper/utils/ternary.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Author: lixu lixu@puchigames.com * @Date: 2025-06-16 10:28:18 * @LastEditors: lixu lixu@puchigames.com * @LastEditTime: 2025-06-16 10:40:09 * @FilePath: /go-helper/utils/time.go * @Description: 时间处理工具函数,包含时间格式化、时间计算、时间比较、时区转换等功能
Index ¶
- Constants
- Variables
- func Abs[T int | int64 | float64](n T) T
- func AbsFloat64(f float64) float64
- func AbsInt(n int) int
- func AbsInt64(n int64) int64
- func AddDays(t time.Time, days int) time.Time
- func AddMonths(t time.Time, months int) time.Time
- func AddYears(t time.Time, years int) time.Time
- func All[T any](arr []T, f func(T) bool) bool
- func Any[T any](arr []T, f func(T) bool) bool
- func AppendFile(path string, data []byte) error
- func AppendFileString(path string, content string) error
- func Average[T int | int64 | float64](numbers []T) float64
- func AverageFloat64(numbers []float64) float64
- func AverageInt(numbers []int) float64
- func Base64Decode(str string) (string, error)
- func Base64Encode(str string) string
- func Base64URLDecode(str string) (string, error)
- func Base64URLEncode(str string) string
- func BuildUrl(baseUrl string, params map[string]string) string
- func CamelCase(str string) string
- func Capitalize(str string) string
- func Ceil(f float64) int
- func Clamp[T int | int64 | float64](value, min, max T) T
- func ClampFloat64(value, min, max float64) float64
- func ClampInt(value, min, max int) int
- func Coalesce[T comparable](values ...T) T
- func CompareVersion(v1, v2 string) int
- func Concat[T any](slices ...[]T) []T
- func Contains[T comparable](arr []T, v T) bool
- func CopyFile(src, dst string) error
- func CopyStruct(src, dst interface{}) error
- func CreateDir(path string) error
- func CurrentDate() string
- func CurrentTime() string
- func CurrentTimeLong() string
- func CurrentTimeRFC() string
- func CurrentTimeShort() string
- func CurrentUnix() int64
- func CurrentUnixMilli() int64
- func CurrentUnixNano() int64
- func Default[T comparable](v, def T) T
- func Delete(url string, config ...*HttpConfig) (*http.Response, error)
- func DeleteDir(path string) error
- func DeleteFile(path string) error
- func DiffDays(t1, t2 time.Time) int
- func DiffMonths(t1, t2 time.Time) int
- func DiffYears(t1, t2 time.Time) int
- func Difference[T comparable](a, b []T) []T
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfWeek(t time.Time) time.Time
- func EndOfYear(t time.Time) time.Time
- func ExcelToStruct(path string, result interface{}) error
- func ExcelToStructWithSheet(path string, sheetName string, result interface{}) error
- func FileExists(path string) bool
- func FileModTime(path string) (time.Time, error)
- func FileMode(path string) (os.FileMode, error)
- func FileSize(path string) (int64, error)
- func FileSizeFormat(size int64) string
- func Filter[T any](arr []T, f func(T) bool) []T
- func Floor(f float64) int
- func FormatDuration(d time.Duration) string
- func FormatTime(t time.Time, format string) string
- func GCD(a, b int) int
- func GenerateAPIKey() string
- func GenerateNanoID(size int) string
- func GenerateObjectID() string
- func GenerateOrderID() string
- func GenerateRequestID() string
- func GenerateSecretKey() string
- func GenerateSessionID() string
- func GenerateShortID() string
- func GenerateShortIDWithLength(length int) string
- func GenerateShortUUID() string
- func GenerateSimpleUUID() string
- func GenerateSnowflakeID() int64
- func GenerateSpanID() string
- func GenerateTraceID() string
- func GenerateUUID() string
- func GenerateUUIDv1() string
- func GenerateUUIDv4() string
- func Get(url string, config ...*HttpConfig) (*http.Response, error)
- func GetAge(birthday time.Time) int
- func GetAllMACAddresses() map[string]string
- func GetChinaLocation() *time.Location
- func GetCookie(resp *http.Response, name string) *http.Cookie
- func GetCookies(resp *http.Response) []*http.Cookie
- func GetCurrentTimezone() string
- func GetCurrentTimezoneAbbr() string
- func GetCurrentTimezoneOffset() int
- func GetDaysInMonth(year int, month time.Month) int
- func GetDomainIP(domain string) []string
- func GetDomainIPWithTimeout(domain string, timeout time.Duration) []string
- func GetDomainIPv4(domain string) []string
- func GetDomainIPv6(domain string) []string
- func GetExcelSheets(path string) ([]string, error)
- func GetFileExt(path string) string
- func GetFileName(path string) string
- func GetFilePath(path string) string
- func GetFreePort() (int, error)
- func GetLocalIP() string
- func GetLocalIPs() []string
- func GetLocalLocation() *time.Location
- func GetLocation(timezone string) (*time.Location, error)
- func GetMACAddress() string
- func GetPublicIP() string
- func GetQuarter(t time.Time) int
- func GetStructFieldType(obj interface{}, fieldName string) (reflect.Type, error)
- func GetStructFieldValue(obj interface{}, fieldName string) (interface{}, error)
- func GetStructFields(obj interface{}) []string
- func GetStructTags(obj interface{}, tagName string) map[string]string
- func GetTimezoneAbbr(timezone string) (string, error)
- func GetTimezoneList() []string
- func GetTimezoneName(timezone string) (string, error)
- func GetTimezoneOffset(timezone string) (int, error)
- func GetUTCLocation() *time.Location
- func GetWeekNumber(t time.Time) int
- func HMACMD5(key, str string) string
- func HMACSHA1(key, str string) string
- func HMACSHA256(key, str string) string
- func HMACSHA512(key, str string) string
- func HasStructField(obj interface{}, fieldName string) bool
- func HexDecode(str string) (string, error)
- func HexEncode(str string) string
- func HttpRequest(method, url string, body interface{}, config *HttpConfig) (*http.Response, error)
- func IPToInt(ip string) uint32
- func IfErr[T any](err error, a, b T) T
- func InRange[T int | int64 | float64](value, min, max T) bool
- func InRangeFloat64(value, min, max float64) bool
- func InRangeInt(value, min, max int) bool
- func IndexOf[T comparable](arr []T, v T) int
- func IntToIP(ipInt uint32) string
- func Intersect[T comparable](a, b []T) []T
- func IsAlpha(str string) bool
- func IsAlphaNumeric(str string) bool
- func IsBlank(str string) bool
- func IsConnectionError(err error) bool
- func IsCurrentDST() bool
- func IsDST(timezone string) (bool, error)
- func IsDir(path string) bool
- func IsEmail(str string) bool
- func IsEmpty(v interface{}) bool
- func IsEven(n int) bool
- func IsFile(path string) bool
- func IsFloat(str string) bool
- func IsIP(str string) bool
- func IsIPv4(str string) bool
- func IsIPv6(str string) bool
- func IsInteger(str string) bool
- func IsLeapYear(year int) bool
- func IsLocalhost(host string) bool
- func IsNil(v interface{}) bool
- func IsNotBlank(str string) bool
- func IsNotEmpty(str string) bool
- func IsNumeric(str string) bool
- func IsOdd(n int) bool
- func IsPhone(str string) bool
- func IsPortOpen(host string, port int) bool
- func IsPortOpenWithTimeout(host string, port int, timeout time.Duration) bool
- func IsPrivateIP(ip string) bool
- func IsPublicIP(ip string) bool
- func IsSameDay(t1, t2 time.Time) bool
- func IsTimeoutError(err error) bool
- func IsToday(t time.Time) bool
- func IsURL(str string) bool
- func IsValidDomain(domain string) bool
- func IsValidIP(ip string) bool
- func IsValidIPv4(ip string) bool
- func IsValidIPv6(ip string) bool
- func IsValidJson(str string) bool
- func IsValidPort(port int) bool
- func IsValidTimezone(timezone string) bool
- func IsWeekend(t time.Time) bool
- func IsWorkday(t time.Time) bool
- func JoinHostPort(host string, port int) string
- func JsonDecode(data string, v interface{}) error
- func JsonDecodeFile(filename string, v interface{}) error
- func JsonDecodeStream(r io.Reader, v interface{}) error
- func JsonEncode(v interface{}) (string, error)
- func JsonEncodeFile(v interface{}, filename string) error
- func JsonEncodePretty(v interface{}) (string, error)
- func JsonEncodeStream(v interface{}, w io.Writer) error
- func JsonGetField(data string, field string) (interface{}, error)
- func JsonMerge(json1, json2 string) (string, error)
- func JsonSetField(data string, field string, value interface{}) (string, error)
- func JsonToStruct(data string, result interface{}) error
- func KebabCase(str string) string
- func LCM(a, b int) int
- func ListDir(path string) ([]string, error)
- func ListDirRecursive(path string) ([]string, error)
- func LowerCase(str string) string
- func MD5(str string) string
- func MD5Bytes(data []byte) string
- func MD5File(filePath string) (string, error)
- func Map[T any, R any](arr []T, f func(T) R) []R
- func MapToStruct(data map[string]interface{}, result interface{}) error
- func MapToStructWithTag(data map[string]interface{}, result interface{}, tagName string) error
- func Max[T int | int64 | float64](a, b T) T
- func MaxFloat64(a, b float64) float64
- func MaxInt(a, b int) int
- func MaxInt64(a, b int64) int64
- func MaxSlice[T int | int64 | float64](numbers []T) T
- func MaxSliceInt(numbers []int) int
- func Min[T int | int64 | float64](a, b T) T
- func MinFloat64(a, b float64) float64
- func MinInt(a, b int) int
- func MinInt64(a, b int64) int64
- func MinSlice[T int | int64 | float64](numbers []T) T
- func MinSliceInt(numbers []int) int
- func MoveFile(src, dst string) error
- func MustBool(v interface{}) bool
- func MustCopyStruct(src, dst interface{})
- func MustFloat(v interface{}) float64
- func MustGetStructFieldType(obj interface{}, fieldName string) reflect.Type
- func MustGetStructFieldValue(obj interface{}, fieldName string) interface{}
- func MustInt(v interface{}) int
- func MustInt64(v interface{}) int64
- func MustJsonDecode(data string, v interface{})
- func MustJsonDecodeFile(filename string, v interface{})
- func MustJsonDecodeStream(r io.Reader, v interface{})
- func MustJsonEncode(v interface{}) string
- func MustJsonEncodeFile(v interface{}, filename string)
- func MustJsonEncodePretty(v interface{}) string
- func MustJsonEncodeStream(v interface{}, w io.Writer)
- func MustJsonGetField(data string, field string) interface{}
- func MustJsonMerge(json1, json2 string) string
- func MustJsonSetField(data string, field string, value interface{}) string
- func MustJsonToStruct(data string, result interface{})
- func MustMapToStruct(data map[string]interface{}, result interface{})
- func MustMapToStructWithTag(data map[string]interface{}, result interface{}, tagName string)
- func MustSetStructFieldValue(obj interface{}, fieldName string, value interface{})
- func MustStructToJson(obj interface{}) string
- func MustStructToMap(obj interface{}) map[string]interface{}
- func MustStructToMapWithTag(obj interface{}, tagName string) map[string]interface{}
- func MustType(v interface{}, targetType string) interface{}
- func NewHttpClient(config *HttpConfig) (*http.Client, error)
- func NormalizeHost(hostPort string) string
- func Now() time.Time
- func PadLeft(str string, length int, pad string) string
- func PadRight(str string, length int, pad string) string
- func ParseHostPort(hostPort string) (host string, port int, err error)
- func ParseObjectID(objectID string) (map[string]interface{}, error)
- func ParseSnowflakeID(id int64) map[string]int64
- func ParseTime(timeStr, format string) (time.Time, error)
- func ParseUrl(urlStr string) (*url.URL, error)
- func PascalCase(str string) string
- func PasswordHash(password string) string
- func PasswordVerify(password, hash string) bool
- func Patch(url string, args ...interface{}) (*http.Response, error)
- func Percentage[T int | int64 | float64](part, total T) float64
- func PercentageFloat64(part, total float64) float64
- func PercentageInt(part, total int) float64
- func Ping(host string) bool
- func PingWithTimeout(host string, timeout time.Duration) bool
- func Post(url string, args ...interface{}) (*http.Response, error)
- func PowerFloat64(base, exp float64) float64
- func PowerInt(base, exp int) int
- func PtrOrVal[T any](ptr *T, def T) T
- func Put(url string, args ...interface{}) (*http.Response, error)
- func RandomBool() bool
- func RandomBytes(n int) []byte
- func RandomElement[T any](slice []T) T
- func RandomElements[T any](slice []T, n int) []T
- func RandomFloat64(min, max float64) float64
- func RandomInt(min, max int) int
- func RandomInt64(min, max int64) int64
- func RandomNumberString(n int) string
- func RandomSpecialString(n int) string
- func RandomString(n int) string
- func RandomTime(start, end time.Time) time.Time
- func RandomUUID() string
- func RandomWeight(weights []float64) int
- func ReadCSVWithOptions(path string, options *CSVOptions) ([][]string, error)
- func ReadExcel(path string) ([][]string, error)
- func ReadExcelSheet(path string, sheetName string) ([][]string, error)
- func ReadFile(path string) ([]byte, error)
- func ReadFileLines(path string) ([]string, error)
- func ReadFileString(path string) (string, error)
- func ReadResponse(resp *http.Response) ([]byte, error)
- func ReadResponseJson(resp *http.Response, v interface{}) error
- func ReadResponseString(resp *http.Response) (string, error)
- func Remove[T comparable](arr []T, v T) []T
- func Repeat(str string, count int) string
- func Reverse[T any](arr []T) []T
- func ReverseString(str string) string
- func Round(f float64, precision int) float64
- func SHA1(str string) string
- func SHA1Bytes(data []byte) string
- func SHA256(str string) string
- func SHA256Bytes(data []byte) string
- func SHA512(str string) string
- func SHA512Bytes(data []byte) string
- func SaveConfig(c Config, filename string) error
- func ScanPorts(host string, startPort, endPort int) []int
- func ScanPortsWithTimeout(host string, startPort, endPort int, timeout time.Duration) []int
- func SetStructFieldValue(obj interface{}, fieldName string, value interface{}) error
- func Shuffle[T any](slice []T)
- func SnakeCase(str string) string
- func Sqrt(f float64) float64
- func StartOfDay(t time.Time) time.Time
- func StartOfMonth(t time.Time) time.Time
- func StartOfWeek(t time.Time) time.Time
- func StartOfYear(t time.Time) time.Time
- func StructToExcel(data interface{}, path string) error
- func StructToExcelWithSheet(data interface{}, path string, sheetName string) error
- func StructToJson(obj interface{}) (string, error)
- func StructToMap(obj interface{}) (map[string]interface{}, error)
- func StructToMapWithTag(obj interface{}, tagName string) (map[string]interface{}, error)
- func Sum[T int | int64 | float64](numbers []T) T
- func SumFloat64(numbers []float64) float64
- func SumInt(numbers []int) int
- func Ternary[T any](cond bool, a, b T) T
- func TimeToUnix(t time.Time) int64
- func TimeToUnixMilli(t time.Time) int64
- func TitleCase(str string) string
- func ToBool(v interface{}) (bool, error)
- func ToChina(t time.Time) time.Time
- func ToFloat(v interface{}) (float64, error)
- func ToInt(v interface{}) (int, error)
- func ToInt64(v interface{}) (int64, error)
- func ToLocal(t time.Time) time.Time
- func ToLocation(t time.Time, timezone string) (time.Time, error)
- func ToStr(v interface{}) string
- func ToType(v interface{}, targetType string) (interface{}, error)
- func ToUTC(t time.Time) time.Time
- func Today() time.Time
- func Tomorrow() time.Time
- func Trim(str string) string
- func TrimLeft(str, cutset string) string
- func TrimRight(str, cutset string) string
- func Truncate(str string, length int, suffix string) string
- func Union[T comparable](a, b []T) []T
- func Unique[T comparable](arr []T) []T
- func UnixMilliToTime(timestamp int64) time.Time
- func UnixToTime(timestamp int64) time.Time
- func UploadFile(url string, fieldName, filePath string, extraFields map[string]string, ...) (*http.Response, error)
- func UpperCase(str string) string
- func ValidateExcelStruct(structType reflect.Type) error
- func ValidateObjectID(objectID string) bool
- func ValidateUUID(uuid string) bool
- func WriteCSVWithOptions(data [][]string, path string, options *CSVOptions) error
- func WriteExcel(data [][]string, path string) error
- func WriteExcelSheet(data [][]string, path string, sheetName string) error
- func WriteFile(path string, data []byte) error
- func WriteFileLines(path string, lines []string) error
- func WriteFileString(path string, content string) error
- func Yesterday() time.Time
- type AtomicBool
- type AtomicInt64
- type Barrier
- type BasicAuth
- type CSVOptions
- type Config
- type ConnectionTest
- type ExcelInfo
- type HttpConfig
- type Mutex
- type NetworkInterface
- type ObjectIDGenerator
- type Once
- type Pool
- type RWMutex
- type Semaphore
- type SnowflakeGenerator
- type WaitGroup
Constants ¶
const ( // 时间格式化模板 TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" TimeFormatShort = "2006-01-02 15:04" TimeFormatLong = "2006-01-02 15:04:05.000" TimeFormatRFC = time.RFC3339 )
Variables ¶
var DefaultHttpConfig = HttpConfig{ Timeout: 30 * time.Second, RetryTimes: 3, RetryDelay: time.Second, Headers: map[string]string{ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", }, MaxRedirect: 5, }
DefaultHttpConfig 默认HTTP配置
var DefaultValue = struct { Int int Int64 int64 Float float64 Bool bool String string }{ Int: 0, Int64: 0, Float: 0.0, Bool: false, String: "", }
DefaultValue 定义默认值
var ErrCancelled = errors.New("operation cancelled")
ErrCancelled 取消错误
var ErrTimeout = errors.New("operation timed out")
ErrTimeout 超时错误
Functions ¶
func AppendFileString ¶
AppendFileString 追加字符串到文件
func Base64URLDecode ¶
Base64URLDecode URL安全的Base64解码
func Coalesce ¶
func Coalesce[T comparable](values ...T) T
Coalesce 返回第一个非零值,否则返回默认值 s := Coalesce("", "默认值", "其他") // 返回 "默认值"
func CompareVersion ¶
CompareVersion 比较版本号大小 返回值:1表示v1>v2,-1表示v1<v2,0表示v1=v2 支持格式:1.2.3、v1.2.3、1.2.3-alpha、1.2.3.4等
func CurrentTimeLong ¶
func CurrentTimeLong() string
CurrentTimeLong 获取当前时间字符串(长格式),格式:2006-01-02 15:04:05.000
func CurrentTimeShort ¶
func CurrentTimeShort() string
CurrentTimeShort 获取当前时间字符串(短格式),格式:2006-01-02 15:04
func Delete ¶
func Delete(url string, config ...*HttpConfig) (*http.Response, error)
Delete 发送DELETE请求
func Difference ¶
func Difference[T comparable](a, b []T) []T
Difference 求 a 相对于 b 的差集(a 中有而 b 中没有的元素)
func ExcelToStruct ¶
ExcelToStruct Excel转结构体切片
func ExcelToStructWithSheet ¶
ExcelToStructWithSheet Excel转结构体切片(指定工作表)
func GenerateShortIDWithLength ¶
GenerateShortIDWithLength 生成指定长度的短ID
func GetAllMACAddresses ¶
GetAllMACAddresses 获取所有网络接口的MAC地址
func GetCurrentTimezoneOffset ¶
func GetCurrentTimezoneOffset() int
GetCurrentTimezoneOffset 获取当前时区与UTC的偏移量(秒)
func GetDomainIPWithTimeout ¶
GetDomainIPWithTimeout 带超时的域名解析
func GetExcelSheets ¶
GetExcelSheets 获取Excel文件的所有工作表名称
func GetStructFieldType ¶
GetStructFieldType 获取结构体指定字段的类型
func GetStructFieldValue ¶
GetStructFieldValue 获取结构体指定字段的值
func GetStructTags ¶
GetStructTags 获取结构体指定tag的所有字段值
func GetTimezoneAbbr ¶
GetTimezoneAbbr 获取指定时区的缩写
func GetTimezoneName ¶
GetTimezoneName 获取指定时区的名称
func GetTimezoneOffset ¶
GetTimezoneOffset 获取指定时区与UTC的偏移量(秒)
func HasStructField ¶
HasStructField 检查结构体是否包含指定字段
func HttpRequest ¶
func HttpRequest(method, url string, body interface{}, config *HttpConfig) (*http.Response, error)
HttpRequest HTTP请求
func InRangeFloat64 ¶
InRangeFloat64 检查浮点数是否在指定范围内(包含边界)
func IsPortOpenWithTimeout ¶
IsPortOpenWithTimeout 带超时的端口检测
func JsonDecodeFile ¶
JsonDecodeFile 从文件读取JSON并解析为指定类型
func JsonDecodeStream ¶
JsonDecodeStream 从io.Reader读取JSON并解析为指定类型
func JsonEncodeFile ¶
JsonEncodeFile 将数据序列化为JSON并写入文件
func JsonEncodePretty ¶
JsonEncodePretty 将任意类型转换为格式化的JSON字符串
func JsonEncodeStream ¶
JsonEncodeStream 将数据序列化为JSON并写入io.Writer
func JsonGetField ¶
JsonGetField 获取JSON字符串中指定字段的值
func JsonSetField ¶
JsonSetField 设置JSON字符串中指定字段的值
func JsonToStruct ¶
JsonToStruct 将JSON字符串转换为结构体
func ListDirRecursive ¶
ListDirRecursive 递归列出目录内容
func MapToStruct ¶
MapToStruct 将map转换为结构体
func MapToStructWithTag ¶
MapToStructWithTag 将map转换为结构体,使用指定的tag作为key
func MustGetStructFieldType ¶
MustGetStructFieldType 强制获取结构体指定字段的类型
func MustGetStructFieldValue ¶
func MustGetStructFieldValue(obj interface{}, fieldName string) interface{}
MustGetStructFieldValue 强制获取结构体指定字段的值
func MustJsonDecode ¶
func MustJsonDecode(data string, v interface{})
MustJsonDecode 强制解码JSON字符串到指定类型
func MustJsonDecodeFile ¶
func MustJsonDecodeFile(filename string, v interface{})
MustJsonDecodeFile 强制从文件读取JSON并解码到指定类型
func MustJsonDecodeStream ¶
MustJsonDecodeStream 强制从流读取JSON并解码到指定类型
func MustJsonEncodeFile ¶
func MustJsonEncodeFile(v interface{}, filename string)
MustJsonEncodeFile 强制将对象编码为JSON并保存到文件
func MustJsonEncodePretty ¶
func MustJsonEncodePretty(v interface{}) string
MustJsonEncodePretty 强制将任意类型转换为格式化的JSON字符串
func MustJsonEncodeStream ¶
MustJsonEncodeStream 强制将对象编码为JSON并写入流
func MustJsonGetField ¶
MustJsonGetField 强制获取JSON字段值
func MustJsonSetField ¶
MustJsonSetField 强制设置JSON字段值
func MustJsonToStruct ¶
func MustJsonToStruct(data string, result interface{})
MustJsonToStruct 强制将JSON字符串转换为结构体
func MustMapToStruct ¶
func MustMapToStruct(data map[string]interface{}, result interface{})
MustMapToStruct 强制将map转换为结构体
func MustMapToStructWithTag ¶
MustMapToStructWithTag 强制将map转换为结构体,使用指定的tag作为key
func MustSetStructFieldValue ¶
func MustSetStructFieldValue(obj interface{}, fieldName string, value interface{})
MustSetStructFieldValue 强制设置结构体指定字段的值
func MustStructToJson ¶
func MustStructToJson(obj interface{}) string
MustStructToJson 强制将结构体转换为JSON字符串
func MustStructToMap ¶
func MustStructToMap(obj interface{}) map[string]interface{}
MustStructToMap 强制将结构体转换为map
func MustStructToMapWithTag ¶
MustStructToMapWithTag 强制将结构体转换为map,使用指定的tag作为key
func MustType ¶
func MustType(v interface{}, targetType string) interface{}
MustType 将任意类型转换为指定类型,转换失败返回默认值
func NewHttpClient ¶
func NewHttpClient(config *HttpConfig) (*http.Client, error)
NewHttpClient 创建HTTP客户端
func ParseHostPort ¶
ParseHostPort 解析主机和端口
func ParseObjectID ¶
ParseObjectID 解析ObjectID
func Percentage ¶
Percentage 泛型版本的百分比计算
func PercentageFloat64 ¶
PercentageFloat64 计算浮点数百分比
func PingWithTimeout ¶
PingWithTimeout 带超时的Ping检测
func RandomFloat64 ¶
RandomFloat64 生成指定范围内的随机float64 [min, max)
func RandomSpecialString ¶
RandomSpecialString 生成指定长度的随机特殊字符字符串
func ReadCSVWithOptions ¶
func ReadCSVWithOptions(path string, options *CSVOptions) ([][]string, error)
ReadCSVWithOptions 使用自定义选项读取CSV
func ReadExcelSheet ¶
ReadExcelSheet 读取Excel文件的指定工作表
func ReadResponseJson ¶
ReadResponseJson 读取响应内容为JSON
func ReadResponseString ¶
ReadResponseString 读取响应内容为字符串
func ScanPortsWithTimeout ¶
ScanPortsWithTimeout 带超时的端口扫描
func SetStructFieldValue ¶
SetStructFieldValue 设置结构体指定字段的值
func StructToExcel ¶
StructToExcel 结构体切片转Excel
func StructToExcelWithSheet ¶
StructToExcelWithSheet 结构体切片转Excel(指定工作表)
func StructToMap ¶
StructToMap 将结构体转换为map
func StructToMapWithTag ¶
StructToMapWithTag 将结构体转换为map,使用指定的tag作为key
func ToLocation ¶
ToLocation 将时间转换到指定时区
func UploadFile ¶
func UploadFile(url string, fieldName, filePath string, extraFields map[string]string, config *HttpConfig) (*http.Response, error)
UploadFile 上传文件
func ValidateExcelStruct ¶
ValidateExcelStruct 验证结构体是否适合Excel转换
func WriteCSVWithOptions ¶
func WriteCSVWithOptions(data [][]string, path string, options *CSVOptions) error
WriteCSVWithOptions 使用自定义选项写入CSV
func WriteExcel ¶
WriteExcel 写入Excel文件,根据扩展名自动选择格式
func WriteExcelSheet ¶
WriteExcelSheet 写入Excel文件的指定工作表
func WriteFileString ¶
WriteFileString 写入字符串到文件
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
AtomicBool 原子布尔值
type AtomicInt64 ¶
type AtomicInt64 struct {
// contains filtered or unexported fields
}
AtomicInt64 原子整数
type Barrier ¶
type Barrier struct {
// contains filtered or unexported fields
}
Barrier 屏障
func (*Barrier) GetNumberWaiting ¶
GetNumberWaiting 获取当前等待的线程数
type CSVOptions ¶
type CSVOptions struct { Comma rune // 分隔符,默认为逗号 Comment rune // 注释符 FieldsPerRecord int // 每条记录的字段数,-1表示可变 LazyQuotes bool // 是否允许懒引号 TrimLeadingSpace bool // 是否去除前导空格 }
CSVOptions CSV读写选项
type Config ¶
type Config interface { Get(key string) interface{} GetString(key string) string GetInt(key string) int GetInt64(key string) int64 GetFloat(key string) float64 GetBool(key string) bool GetStringSlice(key string) []string GetStringMap(key string) map[string]interface{} Set(key string, value interface{}) All() map[string]interface{} }
Config 配置接口
type ConnectionTest ¶
type ConnectionTest struct { Host string `json:"host"` Port int `json:"port"` Protocol string `json:"protocol"` Success bool `json:"success"` Duration time.Duration `json:"duration"` Error string `json:"error,omitempty"` }
TestConnection 测试网络连接
func BatchTestConnections ¶
func BatchTestConnections(hosts []string, ports []int) []ConnectionTest
BatchTestConnections 批量测试连接
func TestTCPConnection ¶
func TestTCPConnection(host string, port int) ConnectionTest
TestTCPConnection 测试TCP连接
func TestUDPConnection ¶
func TestUDPConnection(host string, port int) ConnectionTest
TestUDPConnection 测试UDP连接
type ExcelInfo ¶
type ExcelInfo struct { Path string `json:"path"` Sheets []string `json:"sheets"` TotalRows int `json:"total_rows"` TotalCols int `json:"total_cols"` FileSize int64 `json:"file_size"` ModTime string `json:"mod_time"` }
ExcelInfo Excel文件信息
type HttpConfig ¶
type HttpConfig struct { Timeout time.Duration // 超时时间 RetryTimes int // 重试次数 RetryDelay time.Duration // 重试延迟 Headers map[string]string // 请求头 Cookies []*http.Cookie // Cookie Proxy string // 代理地址 Insecure bool // 是否跳过SSL验证 UserAgent string // User-Agent BasicAuth *BasicAuth // Basic认证 MaxRedirect int // 最大重定向次数 }
HttpConfig HTTP请求配置
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex 增强版的 sync.Mutex,支持超时
type NetworkInterface ¶
type NetworkInterface struct { Name string `json:"name"` HardwareAddr string `json:"hardware_addr"` Flags string `json:"flags"` MTU int `json:"mtu"` IPs []string `json:"ips"` }
NetworkInterface 网络接口信息结构
func GetNetworkInterfaces ¶
func GetNetworkInterfaces() []NetworkInterface
GetNetworkInterfaces 获取网络接口信息
type ObjectIDGenerator ¶
type ObjectIDGenerator struct {
// contains filtered or unexported fields
}
ObjectIDGenerator ObjectID生成器
func (*ObjectIDGenerator) Generate ¶
func (g *ObjectIDGenerator) Generate() string
Generate 生成ObjectID
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex 增强版的 sync.RWMutex,支持超时
type SnowflakeGenerator ¶
type SnowflakeGenerator struct {
// contains filtered or unexported fields
}
SnowflakeGenerator 雪花ID生成器
func NewSnowflakeGenerator ¶
func NewSnowflakeGenerator(workerID, datacenterID int64) (*SnowflakeGenerator, error)
NewSnowflakeGenerator 创建雪花ID生成器
type WaitGroup ¶
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup 增强版的 WaitGroup,支持超时和取消
func NewWaitGroup ¶
NewWaitGroup 创建新的 WaitGroup