utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Array struct {
	Filter func(array []string) (slice []string)
	Remove func(array []string, args ...string) (slice []string)
	Unique func(array []any) (slice []any)
	Empty  func(array []any) (slice []any)
}
View Source
var Format struct {
	Query func(data any) (result string)
}
View Source
var Get struct {
	Type       func(value any) (result string)
	Ip         func(key ...string) (result any)
	Mac        func() (result string)
	Resolution func(index int) (size int)
}
View Source
var In struct {
	Array func(value any, array []any) (ok bool)
}
View Source
var Is struct {
	Ip          func(ip any) (ok bool)
	Url         func(url any) (ok bool)
	Email       func(email any) (ok bool)
	Phone       func(phone any) (ok bool)
	Mobile      func(mobile any) (ok bool)
	Empty       func(value any) (ok bool)
	True        func(value any) (ok bool)
	False       func(value any) (ok bool)
	Number      func(value any) (ok bool)
	Float       func(value any) (ok bool)
	Bool        func(value any) (ok bool)
	Accepted    func(value any) (ok bool)
	Date        func(date any) (ok bool)
	Alpha       func(value any) (ok bool)
	AlphaNum    func(value any) (ok bool)
	AlphaDash   func(value any) (ok bool)
	Chs         func(value any) (ok bool)
	ChsAlpha    func(value any) (ok bool)
	ChsAlphaNum func(value any) (ok bool)
	ChsDash     func(value any) (ok bool)
	Cntrl       func(value any) (ok bool)
	Graph       func(value any) (ok bool)
	Lower       func(value any) (ok bool)
	Upper       func(value any) (ok bool)
	Space       func(value any) (ok bool)
	Xdigit      func(value any) (ok bool)
	ActiveUrl   func(value any) (ok bool)
	Domain      func(domain any) (ok bool)
	IdCard      func(value any) (ok bool)
	MacAddr     func(value any) (ok bool)
	Zip         func(value any) (ok bool)
	String      func(value any) (ok bool)
	Slice       func(value any) (ok bool)
	Array       func(value any) (ok bool)
	JsonString  func(value any) (ok bool)
	Map         func(value any) (ok bool)
	SliceSlice  func(value any) (ok bool)
	MapAny      func(value any) (ok bool)
}
View Source
var Json struct {
	Encode func(value any) (result string)
	Decode func(value any) (result any)
	Get    func(value any, key any) (result any, err error)
}
View Source
var Map struct {
	WithField    func(data map[string]any, field []string) (result map[string]any)
	WithoutField func(data map[string]any, field []string) (result map[string]any)
	ToURL        func(data map[string]any) (result string)
}
View Source
var Mime struct {
	Type func(suffix any) (mime string)
}
View Source
var MimeMap = map[string]string{
	"js":   "application/javascript",
	"json": "application/json",
	"xml":  "application/xml",
	"css":  "text/css",
	"html": "text/html",
	"txt":  "text/plain",
	"gif":  "image/gif",
	"png":  "image/png",
	"jpg":  "image/jpeg",
	"jpeg": "image/jpeg",
	"svg":  "image/svg+xml",
	"ico":  "image/x-icon",
	"pdf":  "application/pdf",
	"zip":  "application/zip",
	"rar":  "application/x-rar-compressed",
	"gz":   "application/x-gzip",
	"tar":  "application/x-tar",
	"7z":   "application/x-7z-compressed",
	"mp3":  "audio/mpeg",
	"mp4":  "video/mp4",
	"avi":  "video/x-msvideo",
	"doc":  "application/msword",
	"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	"xls":  "application/vnd.ms-excel",
	"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	"ppt":  "application/vnd.ms-powerpoint",
	"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
	"csv":  "text/csv",
	"md":   "text/markdown",
}
View Source
var Net struct {
	Tcping func(host any, opts ...map[string]any) (ok bool, detail []map[string]any)
}
View Source
var Parse struct {
	ParamsBefore func(params url.Values) (result map[string]any)
	Params       func(params map[string]any) (result map[string]any)
}
View Source
var Password struct {
	Create func(password any) (result string)
	Verify func(encode any, password any) (ok bool)
}
View Source
var Rand struct {
	Int    func(max int, min ...int) (result int)
	String func(length int, chars ...string) (result string)
}
View Source
var Struct struct {
	Set    func(obj any, key string, val any)
	Get    func(obj any, key string) (result any)
	Del    func(obj any, key string)
	Has    func(obj any, key string) (ok bool)
	Keys   func(obj any) (slice []string)
	Values func(obj any) (slice []any)
	Len    func(obj any) (length int)
	Map    func(obj any) (result map[string]any)
	Slice  func(obj any) (slice []any)
}
View Source
var Unity struct {
	Ids  func(param ...any) (result []any)
	Keys func(param any, reg ...any) (result []any)
}
View Source
var Validate = func(model any) *validator {
	return &validator{
		model: model,
		rule:  ValidateRules,
	}
}

Validate - 验证器入口

View Source
var Version struct {
	Go      func() (version string)
	Compare func(v1 any, v2 any) (result int)
}

Functions

func ArrayEmpty

func ArrayEmpty[T any](array []T) (slice []any)

ArrayEmpty - 数组去空

func ArrayFilter

func ArrayFilter(array []string) (slice []string)

ArrayFilter - 数组过滤

func ArrayRemove

func ArrayRemove(array []string, args ...string) []string

ArrayRemove - 数组删除

func ArrayUnique

func ArrayUnique[T any](array []T) (slice []any)

ArrayUnique - 数组去重

func Calc

func Calc(input any) (output float64)

Calc - 计算器

func Caller

func Caller() *caller

Caller 获取代码调用者

func CustomProcessApi

func CustomProcessApi(url string, api string) (result string)

func Default

func Default[T any](param T, value ...T) (result T)

Default - 设置默认值

func EnvToml

func EnvToml(args ...string) (result any)

EnvToml - 读取配置文件

func ForMap

func ForMap[T any](slice []T, fun func(item T) (result T)) (newSlice []T)

ForMap - 遍历数组,返回新数组

func FormatQuery

func FormatQuery(data any) (result string)

FormatQuery 转 Query 格式

func GetCaller

func GetCaller() (funcName string, fileName string, line int)

func GetIp

func GetIp(key ...string) (result any)

GetIp - 获取客户端IP

func GetMac

func GetMac() (result string)

GetMac - 获取本机MAC

func GetType

func GetType(value any) (result string)

GetType - 获取数据类型

func InArray

func InArray[T any](value T, array []T) (ok bool)

InArray - 判断某个值是否在数组中

func InMapKey

func InMapKey(key string, array map[string]any) bool

InMapKey 在 map key 中

func InMapValue

func InMapValue(value any, array map[string]string) bool

InMapValue 在 map value 中

func IsAccepted

func IsAccepted(value any) (ok bool)

IsAccepted - 验证某个字段是否为为 yes, on, 或是 1

func IsActiveUrl

func IsActiveUrl(value any) (ok bool)

IsActiveUrl - 是否为有效的域名或者IP

func IsAlpha

func IsAlpha(value any) (ok bool)

IsAlpha - 只能包含字母

func IsAlphaDash

func IsAlphaDash(value any) (ok bool)

IsAlphaDash - 只能包含字母、数字和下划线_及破折号-

func IsAlphaNum

func IsAlphaNum(value any) (ok bool)

IsAlphaNum - 只能包含字母和数字

func IsArray

func IsArray(value any) (ok bool)

IsArray - 是否为数组

func IsBool

func IsBool(value any) (ok bool)

IsBool - 是否为bool

func IsChs

func IsChs(value any) (ok bool)

IsChs - 是否为汉字

func IsChsAlpha

func IsChsAlpha(value any) (ok bool)

IsChsAlpha - 只能是汉字、字母

func IsChsAlphaNum

func IsChsAlphaNum(value any) (ok bool)

IsChsAlphaNum - 只能是汉字、字母和数字

func IsChsDash

func IsChsDash(value any) (ok bool)

IsChsDash - 只能是汉字、字母、数字和下划线_及破折号-

func IsCntrl

func IsCntrl(value any) (ok bool)

IsCntrl - 是否为控制字符 - (换行、缩进、空格)

func IsDate

func IsDate(date any) (ok bool)

IsDate - 是否为日期类型

func IsDomain

func IsDomain(domain any) (ok bool)

IsDomain - 是否为域名

func IsEmail

func IsEmail(email any) (ok bool)

IsEmail - 是否为邮箱

func IsEmpty

func IsEmpty(value any) (ok bool)

IsEmpty - 是否为空

func IsFalse

func IsFalse(value any) (ok bool)

IsFalse - 是否为假

func IsFloat

func IsFloat(value any) (ok bool)

IsFloat - 是否为浮点数

func IsGraph

func IsGraph(value any) (ok bool)

IsGraph - 是否为可见字符 - (除空格外的所有可打印字符)

func IsIdCard

func IsIdCard(value any) (ok bool)

IsIdCard - 是否为有效的身份证号码

func IsIp

func IsIp(ip any) (ok bool)

IsIp - 是否为IP

func IsJsonString

func IsJsonString(value any) (ok bool)

IsJsonString - 是否为json字符串

func IsLower

func IsLower(value any) (ok bool)

IsLower - 是否为小写字母

func IsMacAddr

func IsMacAddr(value any) (ok bool)

IsMacAddr - 是否为有效的MAC地址

func IsMap

func IsMap(value any) (ok bool)

IsMap - 是否为map

func IsMapAny

func IsMapAny(value any) (ok bool)

IsMapAny - 是否为[]map[string]any

func IsMobile

func IsMobile(value any) (ok bool)

IsMobile - 是否为手机号

func IsNumber

func IsNumber(value any) (ok bool)

IsNumber - 是否为数字

func IsPhone

func IsPhone(phone any) (ok bool)

IsPhone - 是否为手机号

func IsSlice

func IsSlice(value any) (ok bool)

IsSlice - 是否为切片

func IsSliceSlice

func IsSliceSlice(value any) (ok bool)

IsSliceSlice - 是否为二维切片

func IsSpace

func IsSpace(value any) (ok bool)

IsSpace - 是否为空白字符 - (空格、制表符、换页符等)

func IsString

func IsString(value any) (ok bool)

IsString - 是否为字符串

func IsTrue

func IsTrue(value any) (ok bool)

IsTrue - 是否为真

func IsUpper

func IsUpper(value any) (ok bool)

IsUpper - 是否为大写字母

func IsUrl

func IsUrl(url any) (ok bool)

IsUrl - 是否为URL

func IsXdigit

func IsXdigit(value any) (ok bool)

IsXdigit - 是否为十六进制字符 - (0-9、a-f、A-F)

func IsZip

func IsZip(value any) (ok bool)

IsZip - 是否为有效的邮政编码

func JsonDecode

func JsonDecode(data any) (result any)

JsonDecode 解码

func JsonEncode

func JsonEncode(data any) (result string)

JsonEncode 编码

func JsonGet

func JsonGet(jsonString any, key any) (result any, err error)

JsonGet 获取json中的值 - 支持多级

func MapMerge

func MapMerge(map1 map[any]any, map2 map[any]any) map[any]any

MapMerge map合并

func MapMergeString

func MapMergeString(map1 map[string]string, map2 map[string]string) map[string]string

MapMergeString map合并

func MapToURL

func MapToURL(params map[string]any) (result string)

MapToURL - 无序 map 转 有序 URL

func MapWithField

func MapWithField[T map[string]any](data T, field []string) (result T)

MapWithField - 从map中提取指定字段

func MapWithoutField

func MapWithoutField[T map[string]any](data T, field []string) (result T)

MapWithoutField - 从map中排除指定字段

func MimeType

func MimeType(suffix any) (mime string)

MimeType 获取后缀对应的 mime

func NetTcping

func NetTcping(host any, opts ...map[string]any) (ok bool, detail []map[string]any)

func ParseParams

func ParseParams(params map[string]any) (result map[string]any)

ParseParams - 解析参数 把 Content-Type = application/x-www-form-urlencoded 的参数解析成 map[string]any

func ParseParamsBefore

func ParseParamsBefore(params url.Values) (result map[string]any)

ParseParamsBefore - 解析参数 把 Content-Type = application/x-www-form-urlencoded 的参数解析成 object.deep.age = 10 的格式

func PasswordCreate

func PasswordCreate(password any) (result string)

PasswordCreate - 创建密码

func PasswordVerify

func PasswordVerify(encode any, password any) (ok bool)

PasswordVerify - 验证密码

func RandInt

func RandInt(max int, min ...int) (result int)

RandInt - 生成随机整数

func RandString

func RandString(length int, chars ...string) (result string)

RandString - 生成随机字符串

func Redirect

func Redirect(url any) (result string)

Redirect - 获取重定向地址

func Replace

func Replace(value any, params map[string]any) (result string)

Replace - 字符串替换

func StructDel

func StructDel(obj any, key string)

StructDel - 删除结构体的字段

func StructGet

func StructGet(obj any, key string) (result any)

StructGet - 动态获取结构体的值

func StructHas

func StructHas(obj any, key string) (ok bool)

StructHas - 判断结构体是否存在某个字段

func StructKeys

func StructKeys(obj any) (slice []string)

StructKeys - 获取结构体的字段

func StructLen

func StructLen(obj any) (length int)

StructLen - 获取结构体的长度

func StructMap

func StructMap(obj any) (result map[string]any)

StructMap - 将结构体转换为map

func StructSet

func StructSet(obj any, key string, val any)

StructSet - 动态给结构体赋值

func StructSlice

func StructSlice(obj any) (slice []any)

StructSlice - 将结构体转换为切片

func StructValues

func StructValues(obj any) (slice []any)

StructValues - 获取结构体的值

func Ternary

func Ternary[T any](IF bool, TRUE T, FALSE T) T

Ternary - 三元运算符

func UnityIds

func UnityIds(param ...any) (ids []any)

UnityIds 参数归一化

func UnityKeys

func UnityKeys(param any, reg ...any) (keys []any)

UnityKeys 参数归一化

func ValidateRules

func ValidateRules(name string, value any, rule string, message map[string]string) (err error)

ValidateRules - 验证规则 *

  • @rule - 内置规则 - 如下:
  • required:必填
  • min:最小值
  • max:最大值
  • email:是否为邮箱
  • number:是否为数字
  • float:是否为浮点数
  • bool:是否为布尔值
  • slice:是否为切片 - (数组)
  • jsonStr:是否为 JSON 字符串
  • accepted:验证某个字段是否为为 yes, on, 或是 1
  • date:是否为日期
  • alpha:只能包含字母
  • alphaNum:只能包含字母和数字
  • alphaDash:只能包含字母、数字和下划线_及破折号-
  • chs:只能包含汉字
  • chsAlpha:只能包含汉字、字母
  • chsAlphaNum:只能包含汉字、字母和数字
  • chsDash:只能是汉字、字母、数字和下划线_及破折号-
  • cntrl:是否为控制字符 - (换行、缩进、空格)
  • graph:是否为可见字符 - (除空格外的所有可打印字符)
  • lower:是否为小写字母
  • upper:是否为大写字母
  • space:是否为空白字符 - (空格、制表符、换页符等)
  • xdigit:是否为十六进制字符 - (0-9、a-f、A-F)
  • activeUrl:是否为有效的域名或者IP
  • url:是否为有效的URL地址
  • ip:是否为IP地址
  • mobile:是否为手机号
  • idCard:是否为身份证号
  • MacAddr:是否为MAC地址
  • zip:是否为邮政编码 *

func VersionCompare

func VersionCompare(v1, v2 any) (result int)

VersionCompare - 版本号比对 *

  • @param v1 string - 小版本号
  • @param v2 string - 大版本号
  • @return int - 0: 相等,1: v1 < v2,-1: v1 > v2
  • @example:
  • utils.VersionCompare("1.2.0", "1.0.0") // 1

func VersionGo

func VersionGo() (result string)

VersionGo - 获取当前go版本号

Types

type AsyncStruct

type AsyncStruct[T any] struct {
	// 读写锁
	Mutex sync.RWMutex
	// 等待组
	Wait sync.WaitGroup
	// 数据
	Data T
}

func Async

func Async[T any]() *AsyncStruct[T]

Async - 异步数据

func (*AsyncStruct[T]) Get

func (this *AsyncStruct[T]) Get(key string) any

Get - 获取数据

func (*AsyncStruct[T]) Has

func (this *AsyncStruct[T]) Has(key string) (ok bool)

Has - 判断是否存在

func (*AsyncStruct[T]) Result

func (this *AsyncStruct[T]) Result() T

Result - 获取所有数据

func (*AsyncStruct[T]) Set

func (this *AsyncStruct[T]) Set(key string, val any)

Set - 设置数据

type CurlRequest

type CurlRequest struct {
	Body    any
	Url     string
	Method  string
	Client  *http.Client
	Data    map[string]any
	Query   map[string]any
	Headers map[string]any
}

CurlRequest - 发起请求的结构体

type CurlResponse

type CurlResponse struct {
	StatusCode int
	Request    *http.Request
	Headers    *http.Header
	Body       *io.ReadCloser
	Byte       []byte
	Text       string
	Json       map[string]any
	Error      error
}

CurlResponse - 响应的结构体

type CurlStruct

type CurlStruct struct {
	// contains filtered or unexported fields
}

CurlStruct - Curl 结构体

func Curl

func Curl(request ...CurlRequest) *CurlStruct

Curl - 发起请求 - 入口

func (*CurlStruct) Body

func (this *CurlStruct) Body(body any) *CurlStruct

Body - 定义请求体

func (*CurlStruct) Client

func (this *CurlStruct) Client(client *http.Client) *CurlStruct

Client - 定义请求客户端

func (*CurlStruct) Data

func (this *CurlStruct) Data(key string, value any) *CurlStruct

Data - 定义请求数据

func (*CurlStruct) Datas

func (this *CurlStruct) Datas(data map[string]any) *CurlStruct

Datas - 批量定义请求数据

func (*CurlStruct) Delete

func (this *CurlStruct) Delete(url string) *CurlStruct

Delete - 发起 DELETE 请求

func (*CurlStruct) Get

func (this *CurlStruct) Get(url string) *CurlStruct

Get - 发起 GET 请求

func (*CurlStruct) Header

func (this *CurlStruct) Header(key any, value any) *CurlStruct

Header - 定义请求头

func (*CurlStruct) Headers

func (this *CurlStruct) Headers(headers map[string]any) *CurlStruct

Headers - 批量定义请求头

func (*CurlStruct) Method

func (this *CurlStruct) Method(method string) *CurlStruct

Method - 定义请求类型 - 默认 GET

func (*CurlStruct) Patch

func (this *CurlStruct) Patch(url string) *CurlStruct

Patch - 发起 PATCH 请求

func (*CurlStruct) Post

func (this *CurlStruct) Post(url string) *CurlStruct

Post - 发起 POST 请求

func (*CurlStruct) Put

func (this *CurlStruct) Put(url string) *CurlStruct

Put - 发起 PUT 请求

func (*CurlStruct) Query

func (this *CurlStruct) Query(key any, value any) *CurlStruct

Query - 定义请求参数

func (*CurlStruct) Querys

func (this *CurlStruct) Querys(params map[string]any) *CurlStruct

Querys - 批量定义请求参数

func (*CurlStruct) Send

func (this *CurlStruct) Send() *CurlResponse

Send - 发起请求

func (*CurlStruct) Url

func (this *CurlStruct) Url(url string) *CurlStruct

Url - 定义请求地址

type EnvModel

type EnvModel struct {
	// contains filtered or unexported fields
}

func Env

func Env() *EnvModel

func (*EnvModel) All

func (this *EnvModel) All() (result map[string]any)

func (*EnvModel) Get

func (this *EnvModel) Get(key any, def ...any) (result any)

func (*EnvModel) Mode

func (this *EnvModel) Mode(mode string) *EnvModel

func (*EnvModel) Path

func (this *EnvModel) Path(path string) *EnvModel

func (*EnvModel) TomlAll

func (this *EnvModel) TomlAll() (result any)

type FileCacheClient

type FileCacheClient struct {
	// contains filtered or unexported fields
}

func NewFileCache

func NewFileCache(dir any, expire any, prefix ...any) (*FileCacheClient, error)

NewFileCache - 新建文件缓存 *

  • @param dir 缓存目录
  • @param prefix 缓存名前缀
  • @return *FileCacheClient, error
  • @example:
  • 1. cache, err := facade.NewFileCacheClient("runtime/cache")
  • 2. cache, err := facade.NewFileCacheClient("runtime/cache", "cache_")

func (*FileCacheClient) Clear

func (this *FileCacheClient) Clear() (ok bool)

Clear 清空缓存

func (*FileCacheClient) ClearE

func (this *FileCacheClient) ClearE() (err error)

ClearE 清空缓存

func (*FileCacheClient) Del

func (this *FileCacheClient) Del(key any) (ok bool)

Del 从缓存中删除key对应的数据

func (*FileCacheClient) DelE

func (this *FileCacheClient) DelE(key any) (err error)

DelE 从缓存中删除key对应的数据

func (*FileCacheClient) DelPrefix

func (this *FileCacheClient) DelPrefix(prefix ...any) (ok bool)

DelPrefix 从缓存中删除指定前缀的数据

func (*FileCacheClient) DelPrefixE

func (this *FileCacheClient) DelPrefixE(prefix ...any) (err error)

DelPrefixE 删除指定前缀的缓存

func (*FileCacheClient) DelTags

func (this *FileCacheClient) DelTags(tags ...any) (ok bool)

DelTags 从缓存中删除指定标签的数据

func (*FileCacheClient) DelTagsE

func (this *FileCacheClient) DelTagsE(tag ...any) (err error)

DelTagsE 删除指定标签的缓存

func (*FileCacheClient) Get

func (this *FileCacheClient) Get(key any) (result []byte)

Get 从缓存中获取key对应的数据

func (*FileCacheClient) GetInfo

func (this *FileCacheClient) GetInfo(key any) (info map[string]any)

GetInfo 获取缓存信息

func (*FileCacheClient) GetKeys

func (this *FileCacheClient) GetKeys() (slice []string)

GetKeys 获取所有缓存的key

func (*FileCacheClient) Has

func (this *FileCacheClient) Has(key any) (exist bool)

Has 检查缓存中是否存在key对应的数据

func (*FileCacheClient) Set

func (this *FileCacheClient) Set(key any, value []byte, expire ...any) (ok bool)

Set 将key-value数据加入到缓存中

func (*FileCacheClient) SetE

func (this *FileCacheClient) SetE(key any, value []byte, expire int64) (err error)

SetE 将key-value数据加入到缓存中

type FileCacheClientItem

type FileCacheClientItem struct {
	// contains filtered or unexported fields
}

type FileRequest

type FileRequest struct {
	// 文件名
	Name string
	// 文件路径(包含文件名)
	Path string
	// 目录路径(不包含文件名)
	Dir string
	// 文件后缀
	Ext string
	// 限制行数
	Limit int
	// 读取偏移量
	Page int
	// 返回结果格式
	Format string
	// 是否包含子目录
	Sub bool
	// 域名 - 用于拼接文件路径
	Domain string
	// 前缀 - 用于过滤前缀
	Prefix string
}

FileRequest - File 请求

type FileResponse

type FileResponse struct {
	Error  error
	Result any
	Text   string
	Byte   []byte
	Slice  []any
}

FileResponse - File 响应

type FileStruct

type FileStruct struct {
	// contains filtered or unexported fields
}

FileStruct - File 结构体

func File

func File(request ...FileRequest) *FileStruct

File - 文件系统

func (*FileStruct) Byte

func (this *FileStruct) Byte(path ...any) (result *FileResponse)

Byte 获取文件字节

func (*FileStruct) Dir

func (this *FileStruct) Dir(dir any) *FileStruct

Dir 设置目录路径(不包含文件名,如:/tmp)

func (*FileStruct) DirInfo

func (this *FileStruct) DirInfo(dir ...any) (result *FileResponse)

DirInfo 获取目录信息

func (*FileStruct) Domain

func (this *FileStruct) Domain(domain any) *FileStruct

Domain 设置域名(用于拼接文件路径)

func (*FileStruct) Download

func (this *FileStruct) Download(path ...any) (result *FileResponse)

Download 下载文件 *

  • @param path1 远程文件路径(下载地址)
  • @param path2 本地文件路径(保存路径,包含文件名)
  • @return *FileResponse
  • @example:
  • 1. item := utils.File().Download("https://inis.cn/name.zip", "public/test.zip")
  • 2. item := utils.File().Dir("public").Name("test.zip").Download("https://inis.cn/name.zip")
  • 3. item := utils.File(utils.FileRequest{ Path: "https://inis.cn/name.zip", Name: "test.zip", Dir: "public", }).Download()

func (*FileStruct) EnZip

func (this *FileStruct) EnZip() (result *FileResponse)

EnZip 压缩文件 *

  • @return *FileResponse
  • @example:
  • 1. item := utils.File().Dir("public").Name("name.zip").EnZip()
  • 2. item := utils.File().Dir("public").Path("public/name.zip").EnZip()
  • 3. item := utils.File(utils.FileRequest{ Path: "public/name.zip", Dir: "public", }).EnZip()

func (*FileStruct) Exist

func (this *FileStruct) Exist(path ...any) (ok bool)

Exist 判断文件是否存在

func (*FileStruct) Ext

func (this *FileStruct) Ext(ext any) *FileStruct

Ext 设置文件后缀(如:.txt)

func (*FileStruct) Limit

func (this *FileStruct) Limit(limit any) *FileStruct

Limit 设置限制行数

func (*FileStruct) Line

func (this *FileStruct) Line(path ...any) (result *FileResponse)

Line 按行读取文件

func (*FileStruct) List

func (this *FileStruct) List(path ...any) (result *FileResponse)

List 获取指定目录下的所有文件

func (*FileStruct) Name

func (this *FileStruct) Name(name any) *FileStruct

Name 设置文件名(不包含路径,如:test.txt)

func (*FileStruct) Page

func (this *FileStruct) Page(page any) *FileStruct

Page 设置读取偏移量

func (*FileStruct) Path

func (this *FileStruct) Path(path any) *FileStruct

Path 设置文件路径(包含文件名,如:/tmp/test.txt)

func (*FileStruct) Prefix

func (this *FileStruct) Prefix(prefix any) *FileStruct

Prefix 设置前缀(用于过滤前缀)

func (*FileStruct) Remove

func (this *FileStruct) Remove(path ...any) (result *FileResponse)

Remove 删除文件

func (*FileStruct) Save

func (this *FileStruct) Save(reader io.Reader, path ...string) (result *FileResponse)

Save 保存文件

func (*FileStruct) UnZip

func (this *FileStruct) UnZip() (result *FileResponse)

UnZip 解压文件 *

  • @return *FileResponse
  • @example:
  • 1. item := utils.File().Dir("public").Name("name.zip").UnZip()
  • 2. item := utils.File().Dir("public").Path("public/name.zip").UnZip()
  • 3. item := utils.File(utils.FileRequest{ Path: "public/name.zip", Dir: "public", }).UnZip()

type LangModel

type LangModel struct {
	Directory string // 语言包目录
	Lang      string // 当前语言
	Mode      string // 文件类型
}

func Lang

func Lang(model ...LangModel) *LangModel

Lang 实例化

func (*LangModel) Value

func (this *LangModel) Value(key any, args ...any) (result any)

type ViperModel

type ViperModel struct {
	// 配置文件路径
	Path string
	// 配置文件类型
	Mode string
	// 文件名
	Name string
	// 文件内容
	Content string
}

func Viper

func Viper(model ...ViperModel) *ViperModel

func (*ViperModel) Read

func (this *ViperModel) Read() (result ViperResponse)

func (*ViperModel) SetMode

func (this *ViperModel) SetMode(mode string) *ViperModel

func (*ViperModel) SetName

func (this *ViperModel) SetName(name string) *ViperModel

func (*ViperModel) SetPath

func (this *ViperModel) SetPath(path string) *ViperModel

type ViperResponse

type ViperResponse struct {
	// 配置文件内容
	Result map[string]any
	// 错误信息
	Error error
	// viper实例
	Viper *viper.Viper
}

func (*ViperResponse) Get

func (this *ViperResponse) Get(key string, def ...any) (result any)

func (*ViperResponse) Set

func (this *ViperResponse) Set(key string, value any) (result ViperResponse)

Jump to

Keyboard shortcuts

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