helper

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string, overwrite bool, perm os.FileMode, copyAttr bool) error

CopyFile 复制文件,可设置是否覆盖,可设置文件权限,可设置是否复制文件属性

func CopyFileAttr

func CopyFileAttr(src, dst string) error

CopyFileAttr 复制文件属性

func CreateFile added in v0.2.1

func CreateFile(path string, content []byte, perm os.FileMode, overwrite bool) error

CreateFile 创建文件,可设置文件权限,可设置是否覆盖

func CreateFileIfNotExist deprecated

func CreateFileIfNotExist(path string, content []byte, perm os.FileMode, overwrite bool) error

CreateFileIfNotExist 判断文件是否存在,不存在则根据传入的文件内容创建,可设置文件权限

Deprecated: As of jcbaseGo 0.2.1, this function simply calls CreateFile.

func DirExists

func DirExists(path string, create bool, perm os.FileMode) (bool, error)

DirExists 判断目录是否存在,可选在不存在时是否创建目录

func DirName

func DirName(path string) string

DirName 获取目录部分

func FileExists

func FileExists(path string) bool

FileExists 检查文件是否存在

func GetAbsPath

func GetAbsPath(path string) (string, error)

GetAbsPath 获取绝对路径

func InArray added in v0.1.2

func InArray(val interface{}, array interface{}) (exists bool)

func Int added in v0.3.1

func Int(i int) *int

Int int转换为*int类型

func IsDir

func IsDir(path string) bool

IsDir 判断是否是目录

func IsEmpty

func IsEmpty(path string) bool

IsEmpty 判断文件或目录是否为空

func IsEmptyDir

func IsEmptyDir(path string) bool

IsEmptyDir 判断目录是否为空

func IsEmptyFile

func IsEmptyFile(path string) bool

IsEmptyFile 判断文件是否为空

func IsExecutable

func IsExecutable(path string) bool

IsExecutable 判断文件是否可执行

func IsFile

func IsFile(path string) bool

IsFile 判断是否是文件

func IsHidden

func IsHidden(path string) bool

IsHidden 判断文件是否隐藏

func IsReadable

func IsReadable(path string) bool

IsReadable 判断文件是否可读

func IsSymlink(path string) bool

IsSymlink 判断是否是软链接

func IsWritable

func IsWritable(path string) bool

IsWritable 判断文件是否可写

func JsonStr2Map added in v0.1.2

func JsonStr2Map(str string) map[string]interface{}

func JsonStrSort added in v0.1.2

func JsonStrSort(jsonStr string) string

JsonStrSort 根据map的key进行排序

func ParseIP

func ParseIP(s string) (net.IP, int)

ParseIP 解析IP地址,输出是ipv4或ipv6 0: invalid ip 4: ipv4 6: ipv6

func PasswordHash added in v0.2.1

func PasswordHash(password string) (string, error)

func PasswordVerify added in v0.2.1

func PasswordVerify(password, hash string) bool

func ReadJsonFile

func ReadJsonFile(filePath string, data any) error

ReadJsonFile 读取json文件,并解析到结构体

func Remove

func Remove(path string) error

Remove 删除文件或目录

func Str2Int deprecated added in v0.2.1

func Str2Int(str string) int

Str2Int 字符串转数字

Deprecated: As of jcbaseGo 0.2.1, this function simply calls ToInt.

func StrReplace added in v0.1.2

func StrReplace(search interface{}, replace interface{}, subject interface{}, count int) (interface{}, error)

StrReplace 类似于php中的str_replace

func StringEndWith added in v0.3.1

func StringEndWith(str, suffix string) bool

StringEndWith 判断字符串是否以某个字符串结尾

func StringStartWith added in v0.3.1

func StringStartWith(str, prefix string) bool

StringStartWith 判断字符串是否以某个字符串开头

func ToArrByte added in v0.2.1

func ToArrByte(value interface{}) (arrByte []byte)

ToArrByte 将变量转为[]byte类型

func ToBool added in v0.2.1

func ToBool(value interface{}) (b bool)

ToBool 将变量转为bool类型

func ToFileMode added in v0.2.1

func ToFileMode(value interface{}) (mode os.FileMode)

ToFileMode 将变量转为os.FileMode类型

func ToInt added in v0.2.1

func ToInt(value interface{}) (i int)

ToInt 将变量转为int类型

func ToString added in v0.1.2

func ToString(value interface{}) (key string)

ToString 将变量转为字符串 浮点型 3.0将会转换成字符串3, "3" 非数值或字符类型的变量将会被转换成JSON格式字符串

Types

type ArrStr added in v0.1.2

type ArrStr struct {
	Arr  []string // 数组
	Sort bool     // 执行ArrayValue方法时是否排序
}

func SetArrStr added in v0.1.2

func SetArrStr(str []string) *ArrStr

func (*ArrStr) ArrayDiff added in v0.1.2

func (a *ArrStr) ArrayDiff(oArr ...[]string) (diff []string)

func (*ArrStr) ArrayIntersect added in v0.1.2

func (a *ArrStr) ArrayIntersect(oArr ...[]string) (intersects []string)

func (*ArrStr) ArrayValue added in v0.1.2

func (a *ArrStr) ArrayValue() (value []string)

func (*ArrStr) DoSort added in v0.1.2

func (a *ArrStr) DoSort() *ArrStr

DoSort 设置ArrayValue方法¬是否排序

type JsonStructOpt added in v0.3.1

type JsonStructOpt struct {
	Struct   interface{}            // 结构体
	String   string                 // json字符串
	Map      map[string]interface{} // map
	Sort     bool                   // 是否需要排序
	NeedFile bool                   // 是否需要输出json文件
	FilePath string                 // 输出json文件路径
	// contains filtered or unexported fields
}

func JsonFile added in v0.3.1

func JsonFile(path string) *JsonStructOpt

JsonFile 初始化文件中的json字符串

func JsonString added in v0.3.1

func JsonString(jsonString string) *JsonStructOpt

JsonString 初始化json字符串

func JsonStruct added in v0.3.1

func JsonStruct(jsonStruct interface{}) *JsonStructOpt

JsonStruct 初始化json结构体

func SetStruct added in v0.1.2

func SetStruct(jsonStruct interface{}) *JsonStructOpt

SetStruct Deprecated: 请使用 JsonStruct

func (*JsonStructOpt) DoSort added in v0.3.1

func (opt *JsonStructOpt) DoSort() *JsonStructOpt

DoSort 对json结构根据key重新进行排序

func (*JsonStructOpt) Errors added in v0.3.1

func (opt *JsonStructOpt) Errors() []error

Errors 获取错误信息

func (*JsonStructOpt) File added in v0.3.1

func (opt *JsonStructOpt) File(filepath string) *JsonStructOpt

File 将json输出到

func (*JsonStructOpt) HasError added in v0.3.1

func (opt *JsonStructOpt) HasError() bool

HasError 判断是否有错误

func (*JsonStructOpt) ToJson added in v0.3.1

func (opt *JsonStructOpt) ToJson() (string, error)

ToJson Deprecated: 请使用 ToString

func (*JsonStructOpt) ToString added in v0.3.1

func (opt *JsonStructOpt) ToString(str *string) *JsonStructOpt

ToString 将json字符串以字符串的形式返回

func (*JsonStructOpt) ToStruct added in v0.3.1

func (opt *JsonStructOpt) ToStruct(data interface{}) *JsonStructOpt

type MapStrInterface added in v0.1.2

type MapStrInterface struct {
	Data map[string]interface{}
	Keys []string
	Sort bool
}

func SetMapStrInterface added in v0.1.2

func SetMapStrInterface(data map[string]interface{}) *MapStrInterface

func (*MapStrInterface) ArrayKeys added in v0.1.2

func (d *MapStrInterface) ArrayKeys() []string

func (*MapStrInterface) ArrayValues added in v0.1.2

func (d *MapStrInterface) ArrayValues() []interface{}

func (*MapStrInterface) DoSort added in v0.1.2

func (d *MapStrInterface) DoSort() *MapStrInterface

func (*MapStrInterface) GetData added in v0.1.2

func (d *MapStrInterface) GetData() map[string]interface{}

Jump to

Keyboard shortcuts

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