utils

package module
v0.0.0-...-fad138e Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: AGPL-3.0 Imports: 49 Imported by: 4

README

utils

工具包

Documentation

Index

Constants

View Source
const (
	MimeJpeg      = "image/jpeg"
	MimeJpg       = "image/jpg"
	MimeGif       = "image/gif"
	MimePng       = "image/png"
	MimeHtml      = "text/html"
	MimePdf       = "application/pdf"
	MimeMpeg      = "audio/mpeg"
	MimeQuicktime = "video/quicktime"
	MimeMp4       = "video/mp4"
	MimeWebp      = "image/webp"
	MimeYml       = "application/x-yaml"
	MimeXlsx      = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
	MimeMsExec    = "application/x-ms-dos-executable"
	MimeText      = "text/plain"
)

Variables

View Source
var (
	LowerLetterRunes = []rune("abcdefghijklmnopqrstuvwxyz")
	UpperLetterRunes = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	NumberRunes      = []rune("0123456789")

	LetterRunes          []rune
	LetterAndNumberRules []rune
)
View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func Async

func Async[M any](process int, push func(c chan M), logic func(M))

func CachePanic

func CachePanic()

func CachePanicWithHandle

func CachePanicWithHandle(handle func(err interface{}))

func CamelToSnake

func CamelToSnake(s string) string

func CopyFile

func CopyFile(src, dst string) error

func DialTimeout

func DialTimeout(network, addr string, timeout time.Duration) (time.Duration, error)

func DiffSlice

func DiffSlice(a interface{}, b interface{}) (interface{}, interface{})

DiffSlice 传入两个slice 如果 a 或者 b 不为 slice 会 panic 如果 a 与 b 的元素类型不一致,也会 panic 返回的第一个参数为 a 比 b 多的,类型为 a 的类型 返回的第二个参数为 b 比 a 多的,类型为 b 的类型

func Exit

func Exit()

func FileAppend

func FileAppend(filename string, content string) error

func FileExists

func FileExists(path string) bool

func FileRead

func FileRead(filename string) (content []byte, err error)

func FileReadByLine

func FileReadByLine(fileName string, logic func(line string) error) error

func FileReadWithFs

func FileReadWithFs(filename string, fsys fs.FS) (content []byte, err error)

func FileWrite

func FileWrite(filename string, content string) error

func FormatDuration

func FormatDuration(d time.Duration) string

func FormatTime

func FormatTime(t time.Time) string

func GenGpg

func GenGpg() (*pgp.PGPKeyPair, error)

func GetExecPath

func GetExecPath() string

func GetExitSign

func GetExitSign() chan os.Signal

func GetFileModTime

func GetFileModTime(path string) time.Time

func GetPwd

func GetPwd() string

func GetUserConfigDir

func GetUserConfigDir() string

func GetUserHomeDir

func GetUserHomeDir() string

func GpgDecrypt

func GpgDecrypt(privKey, pubKey string, msg []byte) ([]byte, error)

func GpgEncrypt

func GpgEncrypt(pubKey string, msg string) ([]byte, error)

func HmacMd5

func HmacMd5(key, data string) string

func HmacSha224

func HmacSha224(key, data string) string

func HmacSha256

func HmacSha256(key, data string) string

func HmacSha384

func HmacSha384(key, data string) string

func HmacSha512

func HmacSha512(key, data string) string

func Int2Ip

func Int2Ip(ip int64) net.IP

func Ip2Int

func Ip2Int(ipStr string) int64

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func IsIp

func IsIp(ip string) bool

func IsIpV4

func IsIpV4(ip string) bool

func IsIpV6

func IsIpV6(ip string) bool

func IsLocalIp

func IsLocalIp(ip string) bool

func KeyBy

func KeyBy(list interface{}, fieldName string) interface{}

func MapKeysString

func MapKeysString(m interface{}) []string

func MapValues

func MapValues(m interface{}) interface{}

func Md5

func Md5(s string) string

func MergeCIDRs

func MergeCIDRs(cidrs []string) ([]string, error)

func MergeIPNets

func MergeIPNets(nets []*net.IPNet) ([]*net.IPNet, error)

func MkdirIfNotExists

func MkdirIfNotExists(dir string, perm os.FileMode) error

func Now

func Now() uint32

func PluckInt

func PluckInt(list interface{}, fieldName string) []int

func PluckInt32

func PluckInt32(list interface{}, fieldName string) []int32

func PluckInt64

func PluckInt64(list interface{}, fieldName string) []int64

func PluckString

func PluckString(list interface{}, fieldName string) []string

func PluckStringSlice

func PluckStringSlice(list interface{}, fieldName string) [][]string

func PluckUint32

func PluckUint32(list interface{}, fileName string) []uint32

func PluckUint64

func PluckUint64(list interface{}, fieldName string) []uint64

func PrintStack

func PrintStack()

func ProcessBarAscii

func ProcessBarAscii(total, done int64, wight int64) string

func RandDuration

func RandDuration(min time.Duration, max time.Duration) time.Duration

func RandSleep

func RandSleep(min time.Duration, max time.Duration)

func RandStringLetter

func RandStringLetter(n int) string

func RandStringWithSeed

func RandStringWithSeed(n int, seed []rune) string

func RealIpFromFiberCtx

func RealIpFromFiberCtx(ctx *fiber.Ctx) string

func RemoveSlice

func RemoveSlice(src interface{}, rm interface{}) interface{}

RemoveSlice 传入两个slice 如果 src 或者 rm 不为 slice 会 panic 如果 src 与 rm 的元素类型不一致,也会 panic 返回的第一个参数为 src 中不在 rm 中的元素,数据类型与 src 一致

func Scan

func Scan(src interface{}, dst interface{}) error

func Sha224

func Sha224(s string) string

func Sha256

func Sha256(s string) string

func Sha384

func Sha384(s string) string

func Sha512

func Sha512(s string) string

func ShortStr

func ShortStr(str string, max int) string

func ShortStr4Web

func ShortStr4Web(str string, max int) string

func Slice2Map

func Slice2Map[M constraints.Ordered](list []M) map[M]bool

func SnakeToCamel

func SnakeToCamel(s string) string

func TCPPing

func TCPPing(address string) (time.Duration, error)

func ToBool

func ToBool(val interface{}) bool

func ToFloat32

func ToFloat32(val interface{}) float32

func ToFloat64

func ToFloat64(val interface{}) float64

func ToFloat64Slice

func ToFloat64Slice(val interface{}) []float64

func ToInt

func ToInt(val interface{}) int

func ToInt16

func ToInt16(val interface{}) int16

func ToInt32

func ToInt32(val interface{}) int32

func ToInt64

func ToInt64(val interface{}) int64

func ToInt64Slice

func ToInt64Slice(val interface{}) []int64

func ToInt8

func ToInt8(val interface{}) int8

func ToString

func ToString(val interface{}) string

func ToUint

func ToUint(val interface{}) uint

func ToUint16

func ToUint16(val interface{}) uint16

func ToUint32

func ToUint32(val interface{}) uint32

func ToUint64

func ToUint64(val interface{}) uint64

func ToUint8

func ToUint8(val interface{}) uint8

func UDPPing

func UDPPing(address string) (time.Duration, error)

func Utf16KLen

func Utf16KLen(str string) int

func Validate

func Validate(m interface{}) error

func Value

func Value(m interface{}) (driver.Value, error)

func WaitExist

func WaitExist()

Types

type ContentType

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

func GetContentType

func GetContentType(out io.Reader) (*ContentType, error)

func NewContentType

func NewContentType(raw string) *ContentType

func (*ContentType) MediaType

func (p *ContentType) MediaType() MediaType

func (*ContentType) String

func (p *ContentType) String() string

type Map

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

func NewMap

func NewMap(m map[string]interface{}) *Map

func NewMapWithAny

func NewMapWithAny(s interface{}) (*Map, error)

func NewMapWithJson

func NewMapWithJson(s []byte) (*Map, error)

func NewMapWithYaml

func NewMapWithYaml(s []byte) (*Map, error)

func (*Map) Clone

func (p *Map) Clone() *Map

func (*Map) DisableCut

func (p *Map) DisableCut() *Map

func (*Map) EnableCut

func (p *Map) EnableCut(seq string) *Map

func (*Map) Exists

func (p *Map) Exists(key string) bool

func (*Map) Get

func (p *Map) Get(key string) (interface{}, error)

func (*Map) GetBool

func (p *Map) GetBool(key string) bool

func (*Map) GetBytes

func (p *Map) GetBytes(key string) []byte

func (*Map) GetFloat64

func (p *Map) GetFloat64(key string) float64

func (*Map) GetInt

func (p *Map) GetInt(key string) int

func (*Map) GetInt32

func (p *Map) GetInt32(key string) int32

func (*Map) GetInt64

func (p *Map) GetInt64(key string) int64

func (*Map) GetInt64Slice

func (p *Map) GetInt64Slice(key string) []int64

func (*Map) GetMap

func (p *Map) GetMap(key string) *Map

func (*Map) GetSlice

func (p *Map) GetSlice(key string) []interface{}

func (*Map) GetString

func (p *Map) GetString(key string) string

func (*Map) GetStringSlice

func (p *Map) GetStringSlice(key string) []string

func (*Map) GetUint16

func (p *Map) GetUint16(key string) uint16

func (*Map) GetUint32

func (p *Map) GetUint32(key string) uint32

func (*Map) GetUint32Slice

func (p *Map) GetUint32Slice(key string) []uint32

func (*Map) GetUint64

func (p *Map) GetUint64(key string) uint64

func (*Map) GetUint64Slice

func (p *Map) GetUint64Slice(key string) []uint64

func (*Map) Range

func (p *Map) Range(f func(key, value interface{})) bool

func (*Map) Set

func (p *Map) Set(key string, value interface{})

func (*Map) ToMap

func (p *Map) ToMap() map[string]interface{}

func (*Map) ToSyncMap

func (p *Map) ToSyncMap() *sync.Map

type MediaType

type MediaType uint8
const (
	MediaTypeUnknown MediaType = iota
	MediaApplication
	MediaAudio
	MediaImage
	MediaMultipart
	MediaText
	MediaVideo
	MediaVND
)

func (MediaType) String

func (p MediaType) String() string

type ValueType

type ValueType int
const (
	ValueUnknown ValueType = iota
	ValueNumber
	ValueString
	ValueBool
)

func CheckValueType

func CheckValueType(val interface{}) ValueType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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