util

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthTypeNone             = "none"
	AuthTypeAPIKeyQuery      = "api_key_query"
	AuthTypeAPIKeyHeader     = "api_key_header"
	ApiKeyHeaderPrefixBasic  = "basic"
	ApiKeyHeaderPrefixBearer = "bearer"
	ApiKeyHeaderPrefixCustom = "custom"
	ApiKeyHeaderDefault      = "Authorization"
)

api 鉴权

View Source
const (
	MaxScanTokenSize = 1024 * 1024 // Set the maximum token size to 1 MB
)

Variables

Functions

func AppendFileStream

func AppendFileStream(filePath string, destinationFile *os.File) (int64, error)

func ConvertApiAuthProto added in v0.2.6

func ConvertApiAuthProto(auth *common.ApiAuth) *openapi3_util.Auth

func ConvertApiAuthWebRequestProto added in v0.2.6

func ConvertApiAuthWebRequestProto(auth *common.ApiAuthWebRequest) (*openapi3_util.Auth, error)

func Date2Time added in v0.2.5

func Date2Time(date string) (int64, error)

func DateRange added in v0.2.5

func DateRange(startTs, endTs int64) []string

DateRange 返回[startTs, endTs]闭区间日期列表

func DecryptAES

func DecryptAES(src []byte, key, iv []byte) ([]byte, error)

func DeleteDirFile

func DeleteDirFile(fileDir string) error

func DeleteFile

func DeleteFile(file string) error

func DirFileList

func DirFileList(dir string, subDir bool, fullPath bool) ([]string, error)

func Exist

func Exist[T ~int | ~int32 | ~uint32 | ~int64 | ~string](arr []T, n T) bool

func FileEOF

func FileEOF(err error) bool

func FileExist

func FileExist(filePath string) (bool, error)

func FileExt

func FileExt(filePath string) string

func GenApiUUID

func GenApiUUID() string

func GenUUID

func GenUUID() string

func I32

func I32(s string) (int32, error)

func I64

func I64(s string) (int64, error)

func InitTimeLocal

func InitTimeLocal() error

func InitValidator added in v0.1.4

func InitValidator() error

InitValidator validator中文本地化

func Int2Str

func Int2Str[T ~int | ~int32 | ~uint32 | ~int64](i T) string

func IsAlphanumeric

func IsAlphanumeric(input string) bool

IsAlphanumeric 特殊字符校验

func LoadConfig

func LoadConfig(in string, cfg interface{}) error

func MD5

func MD5(str []byte) string

func Md2html added in v0.1.6

func Md2html(markdown []byte) (string, error)

markdown->html

func MustI32

func MustI32(s string) int32

func MustI64

func MustI64(s string) int64

func MustU32

func MustU32(s string) uint32

func PreviousDateRange added in v0.2.5

func PreviousDateRange(startDate, endDate string) ([]string, []string, error)

返回上一个周期和当前周期闭区间日期列表

func PrintPanicStack

func PrintPanicStack()

PrintPanicStack recover并打印堆栈 用法:defer util.PrintPanicStack(),注意 defer func() { util.PrintPanicStack() } 是无效的

func PrintPanicStackWithCall

func PrintPanicStackWithCall(postProcessor func(panicOccur bool, recoverError error))

func SHA256

func SHA256(src string) string

func Str2Date

func Str2Date(timeStr string) (int64, error)

func Str2Time

func Str2Time(timeStr string) (int64, error)

func Time2Date added in v0.2.5

func Time2Date(ts int64) string

func Time2MsStr

func Time2MsStr(millSec int64) string

func Time2Str

func Time2Str(millSec int64) string

func ToFileSizeStr

func ToFileSizeStr(fileSize int64) string

ToFileSizeStr fileSize单位是B,转换规则:小于1M为KB,大于等于1M,单位为M,保留两位小数

func U32

func U32(s string) (uint32, error)

func Validate added in v0.1.4

func Validate(s interface{}) error

func WeekStartTime

func WeekStartTime(t time.Time, week int) time.Time

WeekStartTime 某周的开始时间(周一0点),-1上周,0本周,1下周

Types

type ApiAuthWebRequest added in v0.2.6

type ApiAuthWebRequest struct {
	AuthType           string `json:"authType" validate:"required,oneof='none' 'api_key_query' 'api_key_header'"` // 鉴权类型 None 或 请求头 或 查询参数
	ApiKeyHeaderPrefix string `json:"apiKeyHeaderPrefix" validate:"omitempty,oneof='basic' 'bearer' 'custom'"`    // 鉴权头部前缀
	ApiKeyHeader       string `json:"apiKeyHeader"`                                                               // HTTP头部名称
	ApiKeyQueryParam   string `json:"apiKeyQueryParam"`                                                           // 查询参数名称
	ApiKeyValue        string `json:"apiKeyValue"`                                                                // apiKey
}

func (*ApiAuthWebRequest) Check added in v0.2.6

func (req *ApiAuthWebRequest) Check() error

func (*ApiAuthWebRequest) ToOpenapiAuth added in v0.2.6

func (auth *ApiAuthWebRequest) ToOpenapiAuth() (*openapi3_util.Auth, error)

type FileMergeResult

type FileMergeResult struct {
	TotalSuccessCount int64
	TotalLineCount    int64
	TotalByteCount    int64
	FilePath          string
}

func MergeFile

func MergeFile(filePathList []string, mergeFilePath string) (*FileMergeResult, error)

MergeFile 合并文件

Jump to

Keyboard shortcuts

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