tools

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 25 Imported by: 7

README

gotools

Golang basic tools

Documentation

Index

Constants

View Source
const (
	PermFile fs.FileMode = 0666
	PermDir              = 0755

	FileSegmentSize = 8 * 1024 * 1024
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(ciphertext, key string) (string, error)

AES解密

func AesEncrypt

func AesEncrypt(text, key string) (string, error)

AES加密,CBC

func ArrayContains

func ArrayContains(array interface{}, val interface{}) bool

Returns the value is in the array

func ArrayContainsBool

func ArrayContainsBool(array []bool, val bool) bool

Returns the bool value is in the array

func ArrayContainsComplex128

func ArrayContainsComplex128(array []complex128, val complex128) bool

Returns the uint complex128 is in the array

func ArrayContainsComplex64

func ArrayContainsComplex64(array []complex64, val complex64) bool

Returns the uint complex64 is in the array

func ArrayContainsFloat32

func ArrayContainsFloat32(array []float32, val float32) bool

Returns the float32 value is in the array

func ArrayContainsFloat64

func ArrayContainsFloat64(array []float64, val float64) bool

Returns the float64 value is in the array

func ArrayContainsInt

func ArrayContainsInt(array []int, val int) bool

IntContains Returns the int value is in the array

func ArrayContainsInt32

func ArrayContainsInt32(array []int32, val int32) bool

Returns the int32 value is in the array

func ArrayContainsInt64

func ArrayContainsInt64(array []int64, val int64) bool

Returns the int64 value is in the array

func ArrayContainsString

func ArrayContainsString(array []string, val string) bool

Returns the string value is in the array

func ArrayContainsUInt

func ArrayContainsUInt(array []uint, val uint) bool

Returns the uint value is in the array

func ArrayIndex

func ArrayIndex(array interface{}, val interface{}) (index int)

Returns the index position of the val in array

func ArrayIndexBool

func ArrayIndexBool(array []bool, val bool) (index int)

Returns the index position of the bool val in array

func ArrayIndexComplex128

func ArrayIndexComplex128(array []complex128, val complex128) (index int)

Returns the index position of the complex128 val in array

func ArrayIndexComplex64

func ArrayIndexComplex64(array []complex64, val complex64) (index int)

Returns the index position of the complex64 val in array

func ArrayIndexFloat32

func ArrayIndexFloat32(array []float32, val float32) (index int)

Returns the index position of the float32 val in array

func ArrayIndexFloat64

func ArrayIndexFloat64(array []float64, val float64) (index int)

Returns the index position of the float64 val in array

func ArrayIndexInt

func ArrayIndexInt(array []int, val int) (index int)

Returns the index position of the int val in array

func ArrayIndexInt32

func ArrayIndexInt32(array []int32, val int32) (index int)

Returns the index position of the int32 val in array

func ArrayIndexInt64

func ArrayIndexInt64(array []int64, val int64) (index int)

Returns the index position of the int64 val in array

func ArrayIndexString

func ArrayIndexString(array []string, val string) (index int)

Returns the index position of the string val in array

func ArrayIndexUInt

func ArrayIndexUInt(array []uint, val uint) (index int)

Returns the index position of the uint val in array

func DirExists

func DirExists(dirpath string) bool

dir path is exists

func DirExistsOrCreate

func DirExistsOrCreate(dirpath string) error

判断目录是否存在,否则创建

func DirFilesRemove

func DirFilesRemove(dir, regex string) error

func DirSize

func DirSize(path string) (int64, error)

Get dir file total size

func DirSizeFormat

func DirSizeFormat(path string) (string, error)

Get dir file total size and format

func FileAutoReDownloadName

func FileAutoReDownloadName(path string) string

自动对下载地址进行重命名 examples: ~/download/main.go ~/download/main(1).go ~/download/main(2).go

func FileCopy added in v0.0.9

func FileCopy(src, dst string, segmentSize int64) error

func FileExists

func FileExists(filepath string) bool

file is exists 判断地址是否存在

func FileList

func FileList(root string, hasHide bool, isRecursion bool, fn filepath.WalkFunc) error

列举文件列表 root: 遍历的目录 hasHide: 是否包含隐藏文件 isRecursion: 是否递归子文件夹 fn: 需要执行的方法

func FileReadForInterface

func FileReadForInterface(path string, i interface{}) error

func FileReadToMap

func FileReadToMap(path string) (map[string]interface{}, error)

read file content to map instance

func FileWriteWithInterface

func FileWriteWithInterface(path string, data interface{}) error

func FilesMerge added in v0.0.7

func FilesMerge(target string, sources []string, perm fs.FileMode) error

合并文件

func FilesRemove

func FilesRemove(paths []string) error

func FormatFloat

func FormatFloat(f float64, digit int16) float64

format float digit

func FormatSize

func FormatSize(size int64) string

format size to string

func FormatTemplate added in v0.0.9

func FormatTemplate(tpl string, i interface{}) string

format template

func FormatTimeDT added in v0.0.9

func FormatTimeDT(t time.Time) string

func FuncConfirm added in v0.0.9

func FuncConfirm(msg string) bool

func IDGen

func IDGen() string

func MapConverForInterface

func MapConverForInterface(m map[string]interface{}, i interface{}) error

map 转换为 interface

func Md5

func Md5(str string) string

func Md5File

func Md5File(path string) (string, error)

func NewFileFilter added in v0.0.7

func NewFileFilter(root string, handlerFn func(paths []string) error) *filefilter

func PathDirExists added in v0.0.8

func PathDirExists(path string) bool

地址所在的目录是否存在

func PathExists added in v0.0.8

func PathExists(path string) bool

地址是否存在,不区分文件和目录

func StringFromReader

func StringFromReader(r io.Reader) (string, error)

通过 io.Reader 转为 string

func ZipDir added in v0.0.7

func ZipDir(src, dst string) (err error)

func ZipFile added in v0.0.7

func ZipFile(src, dst string) (err error)

Types

type ConfirmFunc added in v0.0.7

type ConfirmFunc func(confirm string) (bool, error)

type FileFilterFunc added in v0.0.7

type FileFilterFunc func(string, os.FileInfo, error) (bool, error)

type FileHandlerFunc added in v0.0.7

type FileHandlerFunc func([]string) error

type URL added in v0.0.7

type URL struct {
	*url.URL
	Homepage string
	Dir      string
	FullName string
	Name     string
}

func URLParse added in v0.0.7

func URLParse(rawURL string) (*URL, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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