fun

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: Apache-2.0 Imports: 28 Imported by: 1

README

bool

package test

import (
	"fmt"
	"github.com/jishulangcom/go-fun"
	"testing"
)

// @title: 变量是否布尔类型
func TestIsBool(t *testing.T) {
	v := true
	is := fun.IsBool(v)
	fmt.Println(is) // true
}

string

package test

import (
	"fmt"
	"github.com/jishulangcom/go-fun"
	"testing"
)

// @title: 生成随机字符
func TestRandString(t *testing.T) {
	str := fun.RandString(10)
	fmt.Println(str) // lIETOH7p1x
}

// @title: 是否手机号
func TestIsMobile(t *testing.T) {
	is := fun.IsMobile("136000001")
	fmt.Println(is) // true
}

// @title: 手机号*号处理
func TestMobileStar(t *testing.T) {
	mobile := fun.MobileStar("136000001")
	fmt.Println(mobile) // 136****01
}

// @title: 是否邮箱
func TestIsEmail(t *testing.T) {
	email := fun.IsEmail("815437877@qq.com")
	fmt.Println(email) // true
}

// @title: string转int
func TestStrToInt(t *testing.T) {
	i, err := fun.StrToInt("123456")
	fmt.Println(i, err) // 123456 <nil>
}

// @title: string转int64
func TestStrToInt64(t *testing.T) {
	i, err := fun.StrToInt64("123456")
	fmt.Println(i, err) // 123456 <nil>
}

// @title: string转uint64
func TestStrToUint64(t *testing.T) {
	i, err := fun.StrToUint64("123456")
	fmt.Println(i, err) // 123456 <nil>
}

// @title: string转float64
func TestStrToFloat64(t *testing.T) {
	i, err := fun.StrToFloat64("123456.789")
	fmt.Println(i, err) // 123456 <nil>
}

// @title: string转*big.float
func TestStrToBigFloat(t *testing.T) {
	i, err := fun.StrToBigFloat("123456.789")
	fmt.Println(i, err) // 123456 <nil>
}

// @title: string转*big.Int
func TestStrToBigInt(t *testing.T) {
	bigInt, ok := fun.StrToBigInt("0.123", 3)
	fmt.Println(bigInt.String(), ok) // 123 true
}

// @title: 某字符串是否存在数组中
func TestStrIsInArr(t *testing.T) {
	arr := []string{"技术狼", "jishulang.com"}
	is := fun.StrIsInArr("技术狼", arr)
	fmt.Println(is) // true
}

Documentation

Overview

【包名:】数组相关函数 【作者:】技术狼

【包名:】数组(php)相关函数 【作者:】技术狼

// @title: 布尔相关函数 // @auth: 技术狼(jishulang.com)

【包名:】客户端相关函数 【作者:】技术狼

【包名:】文件相关函数 【作者:】技术狼

【包名:】浮点相关函数 【作者:】技术狼

【包名:】int相关函数 【作者:】技术狼

【包名:】int相关函数 【作者:】技术狼

【包名:】php相关函数 【作者:】技术狼

【包名:】服务器端相关函数 【作者:】技术狼

// @title: 字符串相关函数 // @auth: 技术狼(jishulang.com)

【包名:】字符(php)串相关函数 【作者:】技术狼

【包名:】xml相关函数 【作者:】技术狼

Index

Constants

View Source
const ORIGIN_TIME = "2006-01-02 15:04:05" //go原始时间

Variables

This section is empty.

Functions

func AesDecryptCBC added in v0.0.2

func AesDecryptCBC(encrypted []byte, key []byte) (decrypted []byte)

func AesDecryptCFB added in v0.0.2

func AesDecryptCFB(encrypted []byte, key []byte) (decrypted []byte)

func AesDecryptECB added in v0.0.2

func AesDecryptECB(encrypted []byte, key []byte) (decrypted []byte)

func AesEncryptCBC added in v0.0.2

func AesEncryptCBC(origData []byte, key []byte) (encrypted []byte)

=================== CBC(密码分组链接模式) ======================

func AesEncryptCFB added in v0.0.2

func AesEncryptCFB(origData []byte, key []byte) (encrypted []byte)

=================== CFB(密码反馈模式) ======================

func AesEncryptECB added in v0.0.2

func AesEncryptECB(origData []byte, key []byte) (encrypted []byte)

=================== ECB(电码本模式) ======================

func ArraySum

func ArraySum(arr interface{}) (sum float64, err error)

【名称:】一维数组求和 【参数:】arr(interface) 【返回:】和(float64),err(error) 【备注:】可用于数组、切片;小数点计算会有精度问题

func BinarySearch added in v0.0.2

func BinarySearch(nums []int, left, right, val int) int

【名称:】二分查找法 【参数:】 【返回:】 【备注:】二分查找的基础是先做排序,然后做二分查找

func BubbleSort added in v0.0.2

func BubbleSort(nums []int)

【名称:】冒泡排序 【参数:】 【返回:】 【备注:】

func BytesToFloat32 added in v0.1.2

func BytesToFloat32(bytes []byte) float32

【名称:】[]byte转float32 【参数:】[]byte 【返回:】float32 【备注:】

func BytesToFloat64 added in v0.1.2

func BytesToFloat64(bytes []byte) float64

【名称:】[]byte转float64 【参数:】[]byte 【返回:】float64 【备注:】

func BytesToIoReader added in v0.1.2

func BytesToIoReader(b []byte) io.Reader

【名称:】[]byte转io.Reader 【参数:】[]byte 【返回:】io.Reader 【备注:】

func CallFun added in v0.0.8

func CallFun(any interface{}, funName string, args ...interface{}) []reflect.Value

【名称:】调用函数(魔法函数) 【参数:】包路由(string),版本号 【返回:】包的绝对地址 【备注:】

func Chop

func Chop(str, charlist string) string

【名称:】从字符串右端移除字符 【参数:】字符串(string),要移除的字符(string) 【返回:】字符串(string) 【备注:】

func Chr

func Chr(ascii int32) string

【名称:】ASCII值返回字符 【参数:】ASCII值(int32) 【返回:】字符(string) 【备注:】

func CurrentDateTime added in v0.0.7

func CurrentDateTime() string

【名称:】获取当前日期时间 【参数:】 【返回:】标准时间(string) 【备注:】时间格式:2021-12-30 23:14:07

func DateTimeStrAadNowSub added in v0.0.7

func DateTimeStrAadNowSub(ts string) (time.Duration, error)

【名称:】一个字符串时间与当前时间的时间差 【参数:】字符串时间(string) 如:2022-05-22 23:59:59 【返回:】time.Duration,error 【备注:】

func DatetimeToTimestamp added in v0.0.2

func DatetimeToTimestamp(str string) int64

【名称:】标准时间转化为时间戳 【参数:】标准时间(string) 【返回:】时间戳(秒)(int64) 【备注:】如2018-01-14 21:45:54 转为 1515937554

func DirCopy added in v0.0.7

func DirCopy(srcPath string, destPath string) error

【名称:】目录复制 【参数:】拷贝路径(string),目标路径 【返回:】error 【备注:】

func DirCreate added in v0.0.7

func DirCreate(dirPath string, perm os.FileMode) error

【名称:】创建目录 【参数:】目录路径(string),权限(os.FileMode) 【返回:】error 【备注:】

func DirEndsWithSlash added in v0.0.7

func DirEndsWithSlash(dirPath string) string

【名称:】目录路径以斜杠结尾 【参数:】路径(string) 【返回:】路径(string) 【备注:】

func DirIsExist added in v0.0.7

func DirIsExist(dirPath string) (bool, error)

【名称:】目录是否存在 【参数:】文件路径(string) 【返回:】布尔 【备注:】

func DirIsExistAndChk added in v0.0.7

func DirIsExistAndChk(dirPath string) (bool, error)

【名称:】目录是否存在,若存在检验是否是目录 【参数:】文件路径(string) 【返回:】布尔 【备注:】

func EmptyStruct added in v0.0.2

func EmptyStruct() interface{}

【名称:】返回空对象 【参数:】 【返回:】{} 【备注:】

func Explode

func Explode(separator, str string) []string

【名称:】字符串打散为数组 【参数:】分割字符串(string),要分割的字符串(string) 【返回:】数组(map[int]string) 【备注:】

func FibonacciFind added in v0.0.2

func FibonacciFind(n int) int

【名称:】斐波拉契数列-迭代法 【参数:】 【返回:】 【备注:】 找出第n位数是什么,时间复杂度是n方

func FibonacciRecursion added in v0.0.2

func FibonacciRecursion(n int) int

【名称:】斐波拉契数列-递归方法 【参数:】 【返回:】 【备注:】 找出第n位数是什么,时间复杂度是n方

func FileCopy added in v0.0.7

func FileCopy(srcPath, destPath string) error

【名称:】文件复制 【参数:】文件路径(string)、目标路径(string) 【返回:】error 【备注:】

func FileGetContents added in v0.0.2

func FileGetContents(filePath string) ([]byte, error)

【名称:】获取文件内容 【参数:】路径(string) 【返回:】文件流([]byte) 【备注:】

func FileIsExist added in v0.0.7

func FileIsExist(filePath string) (bool, error)

【名称:】文件是否存在 【参数:】文件路径(string) 【返回:】布尔 【备注:】

func FilePutContents added in v0.0.2

func FilePutContents(filePath string, content string) error

【名称:】文件写入内容 【参数:】路径(string),内容(string) 【返回:】错误状态(error) 【备注:】

func Float32ToByte added in v0.0.2

func Float32ToByte(float32 float32) []byte

【名称:】float32转byte 【参数:】float32 【返回:】byte 【备注:】

func Float32ToInt added in v0.0.2

func Float32ToInt(float32 float32) int

【名称:】float32转int 【参数:】float32 【返回:】int 【备注:】

func Float32ToInt64 added in v0.0.2

func Float32ToInt64(float64 float64) int64

【名称:】float32转int64 【参数:】float32 【返回:】int64 【备注:】

func Float64ToByte added in v0.0.2

func Float64ToByte(float64 float64) []byte

【名称:】float64转byte 【参数:】float32 【返回:】byte 【备注:】

func Float64ToInt added in v0.0.2

func Float64ToInt(float64 float64) int

【名称:】float64转int 【参数:】float64 【返回:】int 【备注:】

func Float64ToInt64 added in v0.0.2

func Float64ToInt64(float64 float64) int64

【名称:】float64转int64 【参数:】float64 【返回:】int64 【备注:】

func Float64ToStr added in v0.0.2

func Float64ToStr(float64 float64) string

【名称:】float64转string 【参数:】float 【返回:】string 【备注:】

func GetFileContent added in v0.0.9

func GetFileContent(filedir string) ([]byte, error)

【名称:】获取文件内容 【参数:】文件路径(string) 【返回:】[]byte,error 【备注:】

func GetImportPackagePath added in v0.0.7

func GetImportPackagePath(packagePath string, version string) string

【名称:】获取导入包的绝对路径 【参数:】包路由(string),版本号 【返回:】包的绝对地址 【备注:】

func GetType added in v0.0.9

func GetType(variable interface{}) string

【名称:】获取变量类型 【参数:】变量(interface) 【返回:】类型名(string) 【备注:】

func Implode

func Implode(separator string, arr interface{}) string

【名称:】数组分割为字符串 【参数:】分割符(string),数组([]interface), 【返回:】字符串(string) 【备注:】参数arr必须为字符串类型的一维数组

func Int64ToInt added in v0.0.2

func Int64ToInt(int64 int64) int

【名称:】int64转int 【参数:】int64 【返回:】int 【备注:】

func Int64ToStr added in v0.0.2

func Int64ToStr(int64 int64) string

【名称:】int64转string 【参数:】int64 【返回:】string 【备注:】

func IntToFloat64 added in v0.0.2

func IntToFloat64(int int) float64

【名称:】int转int64 【参数:】int 【返回:】int64 【备注:】

func IntToInt64 added in v0.0.2

func IntToInt64(int int) int64

【名称:】int转int64 【参数:】int 【返回:】int64 【备注:】

func IntToStr added in v0.0.2

func IntToStr(int int) string

【名称:】int转字符 【参数:】int 【返回:】string 【备注:】

func IoReader added in v0.1.3

func IoReader(b []byte) io.Reader

【名称:】获取io.Reader 【参数:】 【返回:】*bytes.Buffer 【备注:】

func IoReaderToBytes added in v0.1.2

func IoReaderToBytes(reader io.Reader) []byte

【名称:】io.Reader转[]byte 【参数:】io.Reader 【返回:】[]byte 【备注:】

func IoWriter added in v0.1.3

func IoWriter() *bytes.Buffer

【名称:】获取io.Writer 【参数:】 【返回:】*bytes.Buffer 【备注:】

func IsArray added in v0.0.2

func IsArray(val interface{}) bool

【名称:】变量是否为数组(php) 【参数:】变量(interface) 【返回:】true/false(bool)

func IsBool added in v0.0.2

func IsBool(variable interface{}) bool

@title: 变量是否布尔类型 @param: 变量(interface) @return: true/false(bool) @description: @date: 2022/7/3 21:40

func IsDouble added in v0.0.2

func IsDouble(variable interface{}) bool

【名称:】变量是否浮点类型 【参数:】变量(interface) 【返回:】true/false(bool) 【备注:】

func IsEmail added in v0.0.2

func IsEmail(email string) bool

@title: 是否邮箱 @param: 邮箱(string) @return: true/false(bool) @description: @date: 2022/7/3 21:16

func IsFloat added in v0.0.2

func IsFloat(variable interface{}) bool

【名称:】变量是否浮点类型 【参数:】变量(interface) 【返回:】true/false(bool) 【备注:】

func IsInt added in v0.0.2

func IsInt(variable interface{}) bool

【名称:】变量是否int类型(php) 【参数:】变量(interface) 【返回:】true/false(bool) 【备注:】

func IsMobile added in v0.0.2

func IsMobile(mobile string) bool

@title: 是否手机号 @param: 手机号(string) @return: true/false(bool) @description: @date: 2022/7/3 21:10

func IsNumeric added in v0.0.2

func IsNumeric(variable interface{}) bool

【名称:】变量是否数字类型 【参数:】变量(interface) 【返回:】true/false(bool) 【备注:】

func IsSlice added in v0.0.2

func IsSlice(val interface{}) bool

【名称:】变量是否为切片 【参数:】变量(interface) 【返回:】true/false(bool)

func IsString added in v0.0.2

func IsString(variable interface{}) bool

【名称:】变量是否字符类型 【参数:】变量(interface) 【返回:】true/false(bool) 【备注:】

func Join

func Join(separator string, arr interface{}) string

【名称:】数组分割为字符串 【参数:】分割符(string),数组([]interface), 【返回:】字符串(string)

func Lcfirst

func Lcfirst(str string) string

【名称:】字符首字母转成小写 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Ltrim

func Ltrim(str, charlist string) string

【名称:】移除字符串左侧的字符 【参数:】字符串(string),要移除的字符(string) 【返回:】字符串(string) 【备注:】

func MbStrlen added in v0.0.2

func MbStrlen(str string) int

【名称:】获取字符串的长度 【参数:】字符串(string) 【返回:】长度(int) 【备注:】

func Md5

func Md5(src string) string

【名称:】Md5加密 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Millisecond added in v0.0.7

func Millisecond() int64

【名称:】获取时间戳(毫秒) 【参数:】 【返回:】时间戳(int64) 【备注:】

func MobileStar added in v0.0.2

func MobileStar(mobile string) string

@title: 手机号*号处理 @param: 手机号(string) @return: 加*号的手机号(string) @description: 非手机号则直接返回原字符 @date: 2022/7/3 21:13

func Ord

func Ord(str string) int

【名称:】返回字符串中第一个字符的 ASCII 值 【参数:】字符串(string) 【返回:】ASCII值(int) 【备注:】

func QuickSort added in v0.0.2

func QuickSort(nums []int, left, right int)

【名称:】快速排序 【参数:】 【返回:】 【备注:】

func RandString added in v0.0.2

func RandString(n int) string

@title: 生成随机字符 @param: 个数(int) @return: 字符串(string) @description: a-z,A-Z,0-9 @date: 2022/7/3 21:07

func Rfc3339_to_datetime added in v0.0.2

func Rfc3339_to_datetime(str string) string

【名称:】Rfc3339格式时间转为正常时间 【参数:】Rfc3339时间字符(string) 【返回:】时间字符串(string) 【备注:】如2018-01-14T21:45:54+08:00 转为 2018-01-14 21:45:54

func Rtrim

func Rtrim(str, charlist string) string

@title: 移除字符串右侧的字符 @param: 字符串(string),要移除的字符(string) @return: 字符串(string) @description: @date: 2022/7/4 22:07

func SearchByteSliceIndex added in v0.0.2

func SearchByteSliceIndex(bSrc []byte, b byte) int

[]byte 字节切片 循环查找

func ServeIp added in v0.0.2

func ServeIp() (ip string)

【名称:】获取服务器端IP 【参数:】 【返回:】ip地址(string) 【备注:】

func Sha1

func Sha1(str string) string

【名称:】sha1 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Sha256

func Sha256(str string) string

【名称:】Sha256 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Sha512 added in v0.0.2

func Sha512(src string) string

【名称:】Sha512加密 【参数:】 【返回:】 【备注:】

func Shuffle added in v0.0.2

func Shuffle(arr []int)

【名称:】洗牌算法 【参数:】 【返回:】 【备注:】

func Snowflake added in v0.0.2

func Snowflake(workerId int64) (*snowflakeWorker, error)

【名称:】创建雪花算法节点 【参数:】 【返回:】int64 【备注:】

func StrIsInArr added in v0.0.7

func StrIsInArr(target string, str_array []string) bool

@title: 某字符串是否存在数组中 @param: 字符(string),数组(array) @return: 布尔(bool) @description: @date: 2022/7/3 21:33

func StrIsInString added in v0.0.7

func StrIsInString(target string, strs string) bool

【名称:】某字符是否存在字符串中 【参数:】字符(string),字符串(string) 【返回:】布尔(bool) 【备注:】

func StrRepeat added in v0.0.2

func StrRepeat(input string, multiplier int) string

【名称:】把字符串重复指定的次数 【参数:】字符串(string),次数(int) 【返回:】字符(string) 【备注:】

func StrReplace added in v0.1.4

func StrReplace(strs string, oldStr string, newStr string) string

@title: 字符替换 @param: 要替换的字符串(string),旧字符(string),新字符(string) @return: string @description: @date: 2022/7/4 22:14

func StrToBigFloat added in v0.0.7

func StrToBigFloat(str string) (*big.Float, bool)

@title: string转*big.float @param: 字符串(str) @return: *big.Float, bool @description: @date: 2022/7/3 21:31

func StrToBigInt added in v0.0.7

func StrToBigInt(str string, exp int64) (*big.Int, bool)

@title: string转*big.Int @param: (字符)string,(精度位)int64 @return: *big.Int, bool @description: @auth: 技术狼 @date: 2022/7/3 21:00

func StrToFloat64 added in v0.0.2

func StrToFloat64(str string) (float64, error)

@title: string转float64 @param: 字符串(str) @return: float64, error @description: @date: 2022/7/3 21:29

func StrToInt added in v0.0.2

func StrToInt(str string) (int, error)

@title: string转int @param: 字符串(str) @return: int, error @description: @date: 2022/7/3 21:18

func StrToInt64 added in v0.0.2

func StrToInt64(str string) (int64, error)

@title: string转int64 @param: 字符串(str) @return: int64,error @description: @date: 2022/7/3 21:25

func StrToUint64 added in v0.0.7

func StrToUint64(str string) (uint64, error)

@title: string转uint64 @param: 字符串(str) @return: uint64,error @description: @date: 2022/7/3 21:28

func Strtolower

func Strtolower(str string) string

【名称:】字符转小写 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Strtoupper

func Strtoupper(str string) string

【名称:】字符转大写 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func TimeStampSecond added in v0.0.7

func TimeStampSecond() int64

【名称:】获取时间戳(秒) 【参数:】 【返回:】时间戳(int64) 【备注:】

func TimestampToDatetime added in v0.0.2

func TimestampToDatetime(timestamp int64) string

【名称:】时间戳转化为标准时间 【参数:】时间戳(int64) 【返回:】标准时间(string) 【备注:】如2018-01-14 21:45:54 转为 1515937554

func ToFloat64 added in v0.0.2

func ToFloat64(val interface{}) (f64 float64, err error)

【名称:】转换为 Float64 【参数:】val(interface) 【返回:】和(float64),err(error) 【备注:】

func Trim

func Trim(str, charlist string) string

【名称:】移除字符串两侧的字符 【参数:】字符串(string),要移除的字符(string) 【返回:】字符串(string) 【备注:】

func TrimAll

func TrimAll(str string) string

【名称:】去除全部空格 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Ucfirst

func Ucfirst(str string) string

【名称:】字符首字母转成大写 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func Ucword

func Ucword(str string) string

【名称:】每个单词的首字符转换为大写 【参数:】字符串(string) 【返回:】字符串(string) 【备注:】

func UnsafeBytesToString added in v0.0.8

func UnsafeBytesToString(bytes []byte) string

【名称:】不安全的[]byte转string 【参数:】[]byte 【返回:】string 【备注:】

Types

type EmptyStt added in v0.0.2

type EmptyStt struct{}

type FileInfo added in v0.0.8

type FileInfo struct {
	Name    string    `json:"name"`     // 文件名
	Suffix  string    `json:"suffix"`   // 后缀
	Path    string    `json:"path"`     // 文件路径
	Size    int64     `json:"size"`     // 文件大小
	ModTime time.Time `json:"mod_time"` // 修改时间
}

func DirFilesBySuffix added in v0.0.8

func DirFilesBySuffix(dir string, suffix string) ([]FileInfo, error)

【名称:】获取某目录指定后缀的所有文件 【参数:】目录路径(string),后缀(string) 【返回:】路径(string) 【备注:】

type StructInfoStt added in v0.0.2

type StructInfoStt struct {
	Field    string //字段
	DataType string //数据类型
	Form     string //form
	Json     string //json
}

func StructToArr added in v0.0.2

func StructToArr(data interface{}) []StructInfoStt

【名称:】结构体转换为数组 【参数:】 【返回:】 【备注:】 遍历结构体,提取key和val

Jump to

Keyboard shortcuts

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