helper

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode added in v0.6.1

func Base64Decode(str string) (string, error)

Base64Decode base64解密

func Base64Encode added in v0.6.1

func Base64Encode(str string) string

Base64Encode base64加密

func CheckAndSetDefault added in v0.6.1

func CheckAndSetDefault(i interface{}) error

CheckAndSetDefault 检查结构体中的字段是否为空,如果为空则设置为默认值

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 GenerateSSHKey added in v0.6.1

func GenerateSSHKey() error

GenerateSSHKey 生成 SSH 密钥

func GetAbsPath

func GetAbsPath(path string) (string, error)

GetAbsPath 获取绝对路径

func GetFieldNameByJSONTag added in v0.6.1

func GetFieldNameByJSONTag(objType reflect.Type, jsonKey string) string

GetFieldNameByJSONTag 根据 JSON 标记获取结构体字段名

func GetHostInfo added in v0.6.1

func GetHostInfo(req *http.Request) string

GetHostInfo 从http.Request中获取hostInfo

func GetSSHKey added in v0.6.1

func GetSSHKey() (string, error)

GetSSHKey 获取 SSH 密钥,如果不存在则生成

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 IsError added in v0.6.1

func IsError(errs []error) bool

IsError 判断[]error是否存在错误

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{}

JsonStr2Map Deprecated: 请使用 JsonHelper.ToMap

func JsonStrSort added in v0.1.2

func JsonStrSort(jsonStr string) string

JsonStrSort 根据map的key进行排序 Deprecated: 请使用

func MapToStruct added in v0.6.1

func MapToStruct(mapData interface{}, obj interface{})

MapToStruct 通过reflect将map转换为结构体

func ParseIP

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

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

func Random added in v0.6.1

func Random(length int, numericOnly bool) string

Random 生成随机字符

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 StructToMap added in v0.6.1

func StructToMap(obj interface{}, useJsonTag bool) map[string]interface{}

StructToMap 通过reflect将结构体转换为map

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 JsonHelper added in v0.6.1

type JsonHelper struct {
	Struct interface{}            // 结构体
	String string                 // json字符串
	Map    map[string]interface{} // map
	// contains filtered or unexported fields
}

func JsonFile added in v0.3.1

func JsonFile(path string) *JsonHelper

JsonFile 根据传入的文件路径自动读取文件中的json内容 path: json文件路径

func JsonMap added in v0.6.1

func JsonMap(jsonMap map[string]interface{}) *JsonHelper

func JsonString added in v0.3.1

func JsonString(jsonString string) *JsonHelper

func JsonStruct added in v0.3.1

func JsonStruct(jsonStruct interface{}) *JsonHelper

func SetStruct added in v0.1.2

func SetStruct(jsonStruct interface{}) *JsonHelper

SetStruct Deprecated: 请使用 JsonStruct

func (*JsonHelper) DoSort added in v0.6.1

func (jh *JsonHelper) DoSort() *JsonHelper

DoSort 输出json字符串时是否根据key排序 Deprecated: 不再支持自动排序,有需求时通过MapHelper去排序

func (*JsonHelper) Errors added in v0.6.1

func (jh *JsonHelper) Errors() []error

Errors 获取错误信息

func (*JsonHelper) HasError added in v0.6.1

func (jh *JsonHelper) HasError() bool

HasError 判断是否有错误

func (*JsonHelper) MakeFile added in v0.6.1

func (jh *JsonHelper) MakeFile(filepath string) *JsonHelper

MakeFile 是否生成json文件

func (*JsonHelper) ToFile added in v0.6.1

func (jh *JsonHelper) ToFile() *JsonHelper

func (*JsonHelper) ToJson added in v0.6.1

func (jh *JsonHelper) ToJson() (string, error)

ToJson Deprecated: 请使用 JsonHelper.ToString

func (*JsonHelper) ToMap added in v0.6.1

func (jh *JsonHelper) ToMap(newMap *map[string]interface{}) *JsonHelper

func (*JsonHelper) ToString added in v0.6.1

func (jh *JsonHelper) ToString(newStr *string) *JsonHelper

func (*JsonHelper) ToStruct added in v0.6.1

func (jh *JsonHelper) ToStruct(newStruct interface{}) *JsonHelper

type MapHelper added in v0.6.1

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

func NewMap added in v0.6.1

func NewMap(mapData map[string]interface{}) *MapHelper

func SetMapStrInterface added in v0.1.2

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

SetMapStrInterface Deprecated: 请使用 NewMap

func (*MapHelper) ArrayKeys added in v0.6.1

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

func (*MapHelper) ArrayValues added in v0.6.1

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

func (*MapHelper) DoSort added in v0.6.1

func (d *MapHelper) DoSort() *MapHelper

func (*MapHelper) GetData added in v0.6.1

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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