t

package
v0.0.0-...-863588f Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KB represents the size of a kilobyte.
	KB float64 = 1024
	// MB represents the size of a megabyte.
	MB = 1024 * KB
	// GB represents the size of a gigabyte.
	GB = 1024 * MB
	// TB represents the size of a terabyte.
	TB = 1024 * GB
	// PB represents the size of a petabyte.
	PB = 1024 * TB
)
View Source
const (
	ImageExtJPG  = ".jpg"
	ImageExtJPEG = ".jpeg"
	ImageExtGIF  = ".gif"
	ImageExtPNG  = ".png"
	ImageExtWEBP = ".webp"
)

Variables

View Source
var (
	Validate = &validate{}
)

Functions

func CommandLocal

func CommandLocal(name string, arg ...string) (string, error)

func CommandSSH

func CommandSSH(session *ssh.Session, command string) (string, error)

func FileFormatBytes

func FileFormatBytes(bytesize int64, sigfig ...int) string

func ImageConfig

func ImageConfig(r io.Reader, ext string) (config image.Config, err error)

ImageConfig fs, err := os.Open(imagePath) ext:=strings.ToLower(filepath.Ext(imagePath)) ImageConfig(fs,ext)

func IntExplode

func IntExplode(s, sep string) ([]int, error)

IntExplode 1,2,3=>[]int{1,2,3}

func IntImplode

func IntImplode(is []int, sep string) string

IntImplode []int{1,2,3}=>1,2,3

func IsZero

func IsZero(v any) bool

IsZero reports whether "v" is zero value or no. The given "v" value can complete the Zeroer interface which can be used to customize the behavior for each type of "v".

func NumberMax

func NumberMax[T INumber](numbers []T) (T, error)

func NumberMin

func NumberMin[T INumber](numbers []T) (T, error)

func NumberPercentage

func NumberPercentage[T INumber](a, b T) float64

NumberPercentage 百分比

func NumberPercentageString

func NumberPercentageString[T INumber](a, b T) string

func Pointer

func Pointer[T any](any T) *T

func Rand

func Rand() string

Rand returns a random string.

func RandID

func RandID() string

RandID returns a random id string.

func RandomN

func RandomN(n int) string

RandomN returns a random string with length n.

func RandomNumberN

func RandomNumberN(length int) string

func SSHLoginKey

func SSHLoginKey(hostAddr string, username string, privateKey []byte) (session *ssh.Session, err error)

func SSHLoginPassword

func SSHLoginPassword(hostAddr string, username string, password string) (*ssh.Session, error)

func Seed

func Seed(seed int64)

Seed sets the seed to seed.

func StringsReplaceMap

func StringsReplaceMap(s string, repl map[string]string) string

StringsReplaceMap 您手机注册的验证码为:【变量1】,如有问题请拨打客服电话:【变量2】 repl = map[string]string{"变量1":"111","变量2"::"222"} 您手机注册的验证码为:111,如有问题请拨打客服电话:222

func TimeBetween

func TimeBetween(start, end time.Time, diff time.Duration) bool

TimeBetween 判断开始时间和结束时间是否小于等于diff

func TimeCalendar

func TimeCalendar(start, end time.Time, dayCalendarCallback func(day string, start, end time.Time))

TimeCalendar 根据开始时间和结束时间生成期间每天的开始时间和结束时间

func Uniqid

func Uniqid(prefixs ...string) string

Uniqid 基于以微秒计的当前时间,生成一个唯一的ID

func ValidateStruct

func ValidateStruct(obj any) error

Types

type INumber

type INumber interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type ValidationErrors

type ValidationErrors []error

func (ValidationErrors) Error

func (err ValidationErrors) Error() string

Error concatenates all error elements in SliceValidationError into a single string separated by \n.

type Zeroer

type Zeroer interface {
	IsZero() bool
}

Jump to

Keyboard shortcuts

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