comm

package
v0.0.0-...-377a973 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToFloat32

func ByteToFloat32(bs []byte) float32

二进制byte字节转Float32

func ByteToFloat64

func ByteToFloat64(bs []byte) float64

二进制byte字节转Float64

func BytetoInt

func BytetoInt(bs []byte) int

二进制byte字节转换为int

func ConvertToString

func ConvertToString(src string, srcCode string, tagCode string) string

转换字符编码, "GBK", "UTF-8",GB18030 ,HZGB2312的转换 s := ConvertToString(result, "GBK", "UTF-8") s := ConvertToString(result, "UTF-8", "GBK")

func DecryptAES128

func DecryptAES128(data, key []byte) ([]byte, error)

AES128解密

func EncryptAES128

func EncryptAES128(data, key, iv []byte) ([]byte, error)

AES128加密

func ExtractStr

func ExtractStr(str string, substr string) string

提取以substr分割的中间数据,只取第一个数据.

func Float32ToByte

func Float32ToByte(f32 float32) []byte

Float32转二进制byte字节

func Float64ToByte

func Float64ToByte(f64 float64) []byte

Float64转二进制byte字节

func GetAllfiles

func GetAllfiles(dirPath string, files []string) ([]string, error)

获取目录下的所有文件

func GetCurrentDir

func GetCurrentDir() (string, error)

获取程序运行路径

func GetCurrentPath

func GetCurrentPath() (string, error)

获取程序执行的路径.

func GetDirFiles

func GetDirFiles(dir string) (files []string, err error)

获取当前目录下的文件

func GetFileLineCount

func GetFileLineCount(file io.Reader) (count int, err error)

获取文件的总行数

func GetFileSize

func GetFileSize(filePath string) (fileSize int64, err error)

获取文件大小

func GetRandomInt

func GetRandomInt(start, end int) int

得到[start,end]之间的随机整数,加锁,1纳秒执行。

func GetRandomName

func GetRandomName() string

根据时间戳,生成随机数文件名.

func GetRandomString

func GetRandomString(n int) string

返回随机n个字符串

func GetValidFileName

func GetValidFileName(name string, extName string) string

得到有效的文件名.

func GetZoneTime

func GetZoneTime(zoneName string, timeStr string) (lt time.Time, err error)

根据时区和字符串时间,得到指定时区的时间 GetZoneTime("America/Cordoba", str) GetZoneTime("Asia/Shanghai", str)

func IntToByte

func IntToByte(n int) []byte

int转二进制byte字节

func IsFileExist

func IsFileExist(filePath string) bool

判断文件是否存在

func IsPathExist

func IsPathExist(path string) (bool, error)

判断目录是否存在

func MapToStruct

func MapToStruct(mapData interface{}, structData interface{}) (err error)

将数据是map转为struct,结构体必须是指针.注意:结构体首字母要大写.

func MkDir

func MkDir(dir string) (err error)

创建目录,如果没有就创建。

func NewUUID

func NewUUID() (string, error)

func PKCS7UnPadding

func PKCS7UnPadding(data []byte) []byte

去补码

func ReverseString

func ReverseString(str string) string

翻转字符串

func SliceMapToStruct

func SliceMapToStruct(sliceMapData interface{}, sliceStructData interface{}) (err error)

将数据是[]map转为[]struct.注意:结构体首字母要大写.第二个参数要初始化空的跟第一个参数一样大小.

Types

type SliceData

type SliceData struct {
	Data     interface{}                                     //需要排序的切片
	IsAsc    bool                                            //是否升序(true升序,false降序)
	CompFunc func(data1, data2 interface{}, isAsc bool) bool //用于比较两个数的函数
}

(注意排序对象是:interface{})数据是切片(例如:[]int,[]string,[]int64等),以接口接收切片对象,排序对象是,字符串切片,整型切片,浮点切片

func NewSliceDataSort

func NewSliceDataSort(data interface{}, isAsc bool) (sortObj *SliceData, err error)

func (*SliceData) BinarySearchSort

func (s *SliceData) BinarySearchSort(compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

二分法插入排序.(升序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func (*SliceData) BinarySearchSortIndex

func (s *SliceData) BinarySearchSortIndex(start, end int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

对指定区间数据,利用二分法插入排序.

func (*SliceData) FindLocation

func (s *SliceData) FindLocation(start, end, cur int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool) int

二分法插入排序,查找位置.(升序排序).start开始位置,end结束位置,cur当前位置

func (*SliceData) GetValue

func (s *SliceData) GetValue(idx int) (value interface{})

获取切片的数据

func (*SliceData) QuickSort

func (s *SliceData) QuickSort()

func (*SliceData) QuickSortIndexGo

func (s *SliceData) QuickSortIndexGo(left, right int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

快速排序,递归

func (*SliceData) Swap

func (s *SliceData) Swap(i, j int)

数据交换

type SliceInterfacetSort

type SliceInterfacetSort struct {
	Data     []interface{}                                   //需要排序的切片
	IsAsc    bool                                            //是否升序(true升序,false降序)
	CompFunc func(data1, data2 interface{}, isAsc bool) bool //用于比较两个数的函数
}

(注意排序对象是:[]interface{})数据是切片,切片中每个数据是接口,切片的具体数据可以是,字符串,整型,浮点点的切片.

func NewSliceInterfacetSort

func NewSliceInterfacetSort(data []interface{}, isAsc bool) (sortObj *SliceInterfacetSort)

func (*SliceInterfacetSort) BinarySearchSort

func (s *SliceInterfacetSort) BinarySearchSort(compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

二分法插入排序.(升序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func (*SliceInterfacetSort) BinarySearchSortIndex

func (s *SliceInterfacetSort) BinarySearchSortIndex(start, end int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

对指定区间数据,利用二分法插入排序.

func (*SliceInterfacetSort) FindLocation

func (s *SliceInterfacetSort) FindLocation(start, end, cur int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool) int

二分法插入排序,查找位置.(升序排序).start开始位置,end结束位置,cur当前位置

func (*SliceInterfacetSort) QuickSort

func (s *SliceInterfacetSort) QuickSort()

快速排序

func (*SliceInterfacetSort) QuickSortIndexGo

func (s *SliceInterfacetSort) QuickSortIndexGo(left, right int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

快速排序,递归

func (*SliceInterfacetSort) Swap

func (s *SliceInterfacetSort) Swap(i, j int)

数据交换

type SliceStructBaseData

type SliceStructBaseData struct {
	Data            interface{}                                     //需要排序的切片
	SortStructField int                                             //以结构体中字段索引排序.
	IsAsc           bool                                            //是否升序(true升序,false降序)
	CompFunc        func(data1, data2 interface{}, isAsc bool) bool //用于比较两个数的函数
}

以切片中结构体字段排序,切片中数据是指针结构体(结构体可以是指针结构体,也可以不是指针结构体)(结构体中是基础类型和指针类型) (注意排序对象是:interface{})数据是切片,切片中每个数据是指针结构体.以结构体中字段索引号排序.(注意结构体首字母要大写)

func NewSliceStructBaseData

func NewSliceStructBaseData(data interface{}, sortStructField int, isAsc bool) (sortObj *SliceStructBaseData, err error)

func (*SliceStructBaseData) BinarySearchSort

func (s *SliceStructBaseData) BinarySearchSort(compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

二分法插入排序.(升序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func (*SliceStructBaseData) BinarySearchSortIndex

func (s *SliceStructBaseData) BinarySearchSortIndex(start, end int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

对指定区间数据,利用二分法插入排序.

func (*SliceStructBaseData) FindLocation

func (s *SliceStructBaseData) FindLocation(start, end, cur int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool) int

二分法插入排序,查找位置.(升序排序).start开始位置,end结束位置,cur当前位置

func (*SliceStructBaseData) GetValue

func (s *SliceStructBaseData) GetValue(idx int) (value interface{})

获取切片的数据

func (*SliceStructBaseData) QuickSort

func (s *SliceStructBaseData) QuickSort()

func (*SliceStructBaseData) QuickSortIndexGo

func (s *SliceStructBaseData) QuickSortIndexGo(left, right int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

快速排序,递归

func (*SliceStructBaseData) Swap

func (s *SliceStructBaseData) Swap(i, j int)

数据交换

type SliceStructData

type SliceStructData struct {
	Data            interface{}                                     //需要排序的切片
	SortStructField int                                             //以结构体中字段索引排序.
	IsAsc           bool                                            //是否升序(true升序,false降序)
	CompFunc        func(data1, data2 interface{}, isAsc bool) bool //用于比较两个数的函数
	SwapFunc        func(data interface{}, i, j int)                //用于交换两个数的函数
}

以切片中结构体字段排序,切片中数据是结构体(结构体可以是指针结构体,也可以不是指针结构体)(结构体中可以是所有类型) (注意排序对象是:interface{})数据是切片,切片中每个数据是结构体.以结构体中字段索引号排序.(注意结构体首字母要大写)

func NewSliceStructDataSort

func NewSliceStructDataSort(data interface{}, sortStructField int, isAsc bool, swapFunc func(data interface{}, i, j int)) (sortObj *SliceStructData, err error)

func (*SliceStructData) BinarySearchSort

func (s *SliceStructData) BinarySearchSort(compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

二分法插入排序.(升序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func (*SliceStructData) BinarySearchSortIndex

func (s *SliceStructData) BinarySearchSortIndex(start, end int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

对指定区间数据,利用二分法插入排序.

func (*SliceStructData) FindLocation

func (s *SliceStructData) FindLocation(start, end, cur int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool) int

二分法插入排序,查找位置.(升序排序).start开始位置,end结束位置,cur当前位置

func (*SliceStructData) GetValue

func (s *SliceStructData) GetValue(idx int) (value interface{})

获取切片的数据

func (*SliceStructData) QuickSort

func (s *SliceStructData) QuickSort()

func (*SliceStructData) QuickSortIndexGo

func (s *SliceStructData) QuickSortIndexGo(left, right int, compFunc func(data1, data2 interface{}, isAsc bool) bool, isAsc bool)

快速排序,递归

func (*SliceStructData) Swap

func (s *SliceStructData) Swap(i, j int)

数据交换

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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