mirror of
https://github.com/unti-io/go-utils.git
synced 2025-10-05 08:16:50 +08:00
[v1.5.0] 大规范
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type AsyncStruct[T any] struct {
|
||||
type AsyncClass[T any] struct {
|
||||
// 读写锁
|
||||
Mutex sync.RWMutex
|
||||
// 等待组
|
||||
@@ -16,7 +16,7 @@ type AsyncStruct[T any] struct {
|
||||
}
|
||||
|
||||
// Async - 异步数据
|
||||
func Async[T any]() *AsyncStruct[T] {
|
||||
func Async[T any]() *AsyncClass[T] {
|
||||
|
||||
var data T
|
||||
switch reflect.TypeOf(data).Kind() {
|
||||
@@ -28,7 +28,7 @@ func Async[T any]() *AsyncStruct[T] {
|
||||
data = reflect.Zero(reflect.TypeOf(data)).Interface().(T)
|
||||
}
|
||||
|
||||
return &AsyncStruct[T]{
|
||||
return &AsyncClass[T]{
|
||||
Mutex: sync.RWMutex{},
|
||||
Wait: sync.WaitGroup{},
|
||||
Data: data,
|
||||
@@ -36,7 +36,7 @@ func Async[T any]() *AsyncStruct[T] {
|
||||
}
|
||||
|
||||
// Get - 获取数据
|
||||
func (this *AsyncStruct[T]) Get(key string) any {
|
||||
func (this *AsyncClass[T]) Get(key string) any {
|
||||
|
||||
defer this.Mutex.Unlock()
|
||||
this.Mutex.Lock()
|
||||
@@ -58,7 +58,7 @@ func (this *AsyncStruct[T]) Get(key string) any {
|
||||
}
|
||||
|
||||
// Set - 设置数据
|
||||
func (this *AsyncStruct[T]) Set(key string, val any) {
|
||||
func (this *AsyncClass[T]) Set(key string, val any) {
|
||||
|
||||
defer this.Mutex.Unlock()
|
||||
this.Mutex.Lock()
|
||||
@@ -79,7 +79,7 @@ func (this *AsyncStruct[T]) Set(key string, val any) {
|
||||
}
|
||||
|
||||
// Has - 判断是否存在
|
||||
func (this *AsyncStruct[T]) Has(key string) (ok bool) {
|
||||
func (this *AsyncClass[T]) Has(key string) (ok bool) {
|
||||
|
||||
defer this.Mutex.Unlock()
|
||||
this.Mutex.Lock()
|
||||
@@ -100,7 +100,7 @@ func (this *AsyncStruct[T]) Has(key string) (ok bool) {
|
||||
}
|
||||
|
||||
// Result - 获取所有数据
|
||||
func (this *AsyncStruct[T]) Result() T {
|
||||
func (this *AsyncClass[T]) Result() T {
|
||||
defer this.Mutex.Unlock()
|
||||
this.Mutex.Lock()
|
||||
return this.Data
|
||||
|
@@ -158,12 +158,12 @@ func Calc(input any) (output float64) {
|
||||
return result[0]
|
||||
}
|
||||
|
||||
var Ascii *AsciiStruct
|
||||
var Ascii *AsciiClass
|
||||
|
||||
type AsciiStruct struct {}
|
||||
type AsciiClass struct {}
|
||||
|
||||
// ToString - 根据ASCII码排序
|
||||
func (this *AsciiStruct) ToString(params map[string]any, omitempty bool) (result string) {
|
||||
func (this *AsciiClass) ToString(params map[string]any, omitempty bool) (result string) {
|
||||
|
||||
// 字典排序
|
||||
keys := make([]string, 0, len(params))
|
||||
|
@@ -19,13 +19,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type HashStruct struct{}
|
||||
type HashClass struct{}
|
||||
|
||||
// Hash - 哈希加密
|
||||
var Hash *HashStruct
|
||||
var Hash *HashClass
|
||||
|
||||
// Sum32 - 哈希加密
|
||||
func (this *HashStruct) Sum32(text any) (result string) {
|
||||
func (this *HashClass) Sum32(text any) (result string) {
|
||||
item := fnv.New32()
|
||||
_, err := item.Write([]byte(cast.ToString(text)))
|
||||
return cast.ToString(Ternary[any](err != nil, nil, item.Sum32()))
|
||||
@@ -38,7 +38,7 @@ func (this *HashStruct) Sum32(text any) (result string) {
|
||||
* @example:
|
||||
* token := utils.Hash.Token("test", 16)
|
||||
*/
|
||||
func (this *HashStruct) Token(value any, length int) (result string) {
|
||||
func (this *HashClass) Token(value any, length int) (result string) {
|
||||
|
||||
// 计算 MD5 哈希值
|
||||
hash := md5.Sum([]byte(cast.ToString(value)))
|
||||
@@ -62,7 +62,7 @@ func (this *HashStruct) Token(value any, length int) (result string) {
|
||||
* @example:
|
||||
* 1. number := facade.Hash.Number(6)
|
||||
*/
|
||||
func (this *HashStruct) Number(length any) (result string) {
|
||||
func (this *HashClass) Number(length any) (result string) {
|
||||
|
||||
// 生成一个随机种子
|
||||
rand2.NewSource(time.Now().UnixNano())
|
||||
@@ -178,9 +178,9 @@ func (this *AESRequest) Decrypt(text any) (result *AESResponse) {
|
||||
return
|
||||
}
|
||||
|
||||
var RSA *RSAStruct
|
||||
var RSA *RSAClass
|
||||
|
||||
type RSAStruct struct{}
|
||||
type RSAClass struct{}
|
||||
|
||||
type RSAResponse struct {
|
||||
// 私钥
|
||||
@@ -198,7 +198,7 @@ type RSAResponse struct {
|
||||
* @name Generate 生成 RSA 密钥对
|
||||
* @param bits 位数 1024, 2048, 4096(一般:2048)
|
||||
*/
|
||||
func (this *RSAStruct) Generate(bits any) (result *RSAResponse) {
|
||||
func (this *RSAClass) Generate(bits any) (result *RSAResponse) {
|
||||
|
||||
result = &RSAResponse{}
|
||||
|
||||
@@ -236,7 +236,7 @@ func (this *RSAStruct) Generate(bits any) (result *RSAResponse) {
|
||||
}
|
||||
|
||||
// Encrypt 加密
|
||||
func (this *RSAStruct) Encrypt(publicKey, text string) (result *RSAResponse) {
|
||||
func (this *RSAClass) Encrypt(publicKey, text string) (result *RSAResponse) {
|
||||
|
||||
result = &RSAResponse{}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (this *RSAStruct) Encrypt(publicKey, text string) (result *RSAResponse) {
|
||||
}
|
||||
|
||||
// Decrypt 解密
|
||||
func (this *RSAStruct) Decrypt(privateKey, text string) (result *RSAResponse) {
|
||||
func (this *RSAClass) Decrypt(privateKey, text string) (result *RSAResponse) {
|
||||
|
||||
result = &RSAResponse{}
|
||||
|
||||
@@ -311,7 +311,7 @@ func (this *RSAStruct) Decrypt(privateKey, text string) (result *RSAResponse) {
|
||||
}
|
||||
|
||||
// PublicPem - 输出完整的 PEM 格式公钥证书
|
||||
func (this *RSAStruct) PublicPem(key string) (cert string) {
|
||||
func (this *RSAClass) PublicPem(key string) (cert string) {
|
||||
|
||||
// 创建 PEM 格式块
|
||||
block := &pem.Block{
|
||||
@@ -327,7 +327,7 @@ func (this *RSAStruct) PublicPem(key string) (cert string) {
|
||||
}
|
||||
|
||||
// PrivatePem - 输出完整的 PEM 格式私钥证书
|
||||
func (this *RSAStruct) PrivatePem(key string) (cert string) {
|
||||
func (this *RSAClass) PrivatePem(key string) (cert string) {
|
||||
|
||||
// 创建 PEM 格式块
|
||||
block := &pem.Block{
|
||||
|
@@ -35,14 +35,14 @@ type CurlResponse struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
// CurlStruct - Curl 结构体
|
||||
type CurlStruct struct {
|
||||
// CurlClass - Curl 结构体
|
||||
type CurlClass struct {
|
||||
request *CurlRequest
|
||||
response *CurlResponse
|
||||
}
|
||||
|
||||
// Curl - 发起请求 - 入口
|
||||
func Curl(request ...CurlRequest) *CurlStruct {
|
||||
func Curl(request ...CurlRequest) *CurlClass {
|
||||
|
||||
if len(request) == 0 {
|
||||
request = append(request, CurlRequest{})
|
||||
@@ -68,7 +68,7 @@ func Curl(request ...CurlRequest) *CurlStruct {
|
||||
request[0].Client = &http.Client{}
|
||||
}
|
||||
|
||||
return &CurlStruct{
|
||||
return &CurlClass{
|
||||
request: &request[0],
|
||||
response: &CurlResponse{
|
||||
Json: make(map[string]any),
|
||||
@@ -77,60 +77,60 @@ func Curl(request ...CurlRequest) *CurlStruct {
|
||||
}
|
||||
|
||||
// Get - 发起 GET 请求
|
||||
func (this *CurlStruct) Get(url string) *CurlStruct {
|
||||
func (this *CurlClass) Get(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
this.request.Method = "GET"
|
||||
return this
|
||||
}
|
||||
|
||||
// Post - 发起 POST 请求
|
||||
func (this *CurlStruct) Post(url string) *CurlStruct {
|
||||
func (this *CurlClass) Post(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
this.request.Method = "POST"
|
||||
return this
|
||||
}
|
||||
|
||||
// Put - 发起 PUT 请求
|
||||
func (this *CurlStruct) Put(url string) *CurlStruct {
|
||||
func (this *CurlClass) Put(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
this.request.Method = "PUT"
|
||||
return this
|
||||
}
|
||||
|
||||
// Patch - 发起 PATCH 请求
|
||||
func (this *CurlStruct) Patch(url string) *CurlStruct {
|
||||
func (this *CurlClass) Patch(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
this.request.Method = "PATCH"
|
||||
return this
|
||||
}
|
||||
|
||||
// Delete - 发起 DELETE 请求
|
||||
func (this *CurlStruct) Delete(url string) *CurlStruct {
|
||||
func (this *CurlClass) Delete(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
this.request.Method = "DELETE"
|
||||
return this
|
||||
}
|
||||
|
||||
// Method - 定义请求类型 - 默认 GET
|
||||
func (this *CurlStruct) Method(method string) *CurlStruct {
|
||||
func (this *CurlClass) Method(method string) *CurlClass {
|
||||
this.request.Method = strings.ToUpper(method)
|
||||
return this
|
||||
}
|
||||
|
||||
// Url - 定义请求地址
|
||||
func (this *CurlStruct) Url(url string) *CurlStruct {
|
||||
func (this *CurlClass) Url(url string) *CurlClass {
|
||||
this.request.Url = url
|
||||
return this
|
||||
}
|
||||
|
||||
// Header - 定义请求头
|
||||
func (this *CurlStruct) Header(key any, value any) *CurlStruct {
|
||||
func (this *CurlClass) Header(key any, value any) *CurlClass {
|
||||
this.request.Headers[cast.ToString(key)] = cast.ToString(value)
|
||||
return this
|
||||
}
|
||||
|
||||
// Headers - 批量定义请求头
|
||||
func (this *CurlStruct) Headers(headers map[string]any) *CurlStruct {
|
||||
func (this *CurlClass) Headers(headers map[string]any) *CurlClass {
|
||||
for key, val := range headers {
|
||||
this.request.Headers[cast.ToString(key)] = cast.ToString(val)
|
||||
}
|
||||
@@ -138,13 +138,13 @@ func (this *CurlStruct) Headers(headers map[string]any) *CurlStruct {
|
||||
}
|
||||
|
||||
// Query - 定义请求参数
|
||||
func (this *CurlStruct) Query(key any, value any) *CurlStruct {
|
||||
func (this *CurlClass) Query(key any, value any) *CurlClass {
|
||||
this.request.Query[cast.ToString(key)] = cast.ToString(value)
|
||||
return this
|
||||
}
|
||||
|
||||
// Querys - 批量定义请求参数
|
||||
func (this *CurlStruct) Querys(params map[string]any) *CurlStruct {
|
||||
func (this *CurlClass) Querys(params map[string]any) *CurlClass {
|
||||
for key, val := range params {
|
||||
this.request.Query[cast.ToString(key)] = cast.ToString(val)
|
||||
}
|
||||
@@ -152,13 +152,13 @@ func (this *CurlStruct) Querys(params map[string]any) *CurlStruct {
|
||||
}
|
||||
|
||||
// Data - 定义请求数据
|
||||
func (this *CurlStruct) Data(key string, value any) *CurlStruct {
|
||||
func (this *CurlClass) Data(key string, value any) *CurlClass {
|
||||
this.request.Data[key] = cast.ToString(value)
|
||||
return this
|
||||
}
|
||||
|
||||
// Datas - 批量定义请求数据
|
||||
func (this *CurlStruct) Datas(data map[string]any) *CurlStruct {
|
||||
func (this *CurlClass) Datas(data map[string]any) *CurlClass {
|
||||
for key, val := range data {
|
||||
this.request.Data[key] = cast.ToString(val)
|
||||
}
|
||||
@@ -166,19 +166,19 @@ func (this *CurlStruct) Datas(data map[string]any) *CurlStruct {
|
||||
}
|
||||
|
||||
// Body - 定义请求体
|
||||
func (this *CurlStruct) Body(body any) *CurlStruct {
|
||||
func (this *CurlClass) Body(body any) *CurlClass {
|
||||
this.request.Body = body
|
||||
return this
|
||||
}
|
||||
|
||||
// Client - 定义请求客户端
|
||||
func (this *CurlStruct) Client(client *http.Client) *CurlStruct {
|
||||
func (this *CurlClass) Client(client *http.Client) *CurlClass {
|
||||
this.request.Client = client
|
||||
return this
|
||||
}
|
||||
|
||||
// Send - 发起请求
|
||||
func (this *CurlStruct) Send() *CurlResponse {
|
||||
func (this *CurlClass) Send() *CurlResponse {
|
||||
|
||||
if Is.Empty(this.request.Url) {
|
||||
this.response.Error = errors.New("url is required")
|
||||
|
16
utils/env.go
16
utils/env.go
@@ -58,29 +58,29 @@ func EnvToml(args ...string) (result any) {
|
||||
}
|
||||
}
|
||||
|
||||
type EnvModel struct {
|
||||
type EnvClass struct {
|
||||
path string
|
||||
mode string
|
||||
}
|
||||
|
||||
func Env() *EnvModel {
|
||||
return &EnvModel{
|
||||
func Env() *EnvClass {
|
||||
return &EnvClass{
|
||||
path: "./config/app.toml",
|
||||
mode: "toml",
|
||||
}
|
||||
}
|
||||
|
||||
func (this *EnvModel) Path(path string) *EnvModel {
|
||||
func (this *EnvClass) Path(path string) *EnvClass {
|
||||
this.path = path
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *EnvModel) Mode(mode string) *EnvModel {
|
||||
func (this *EnvClass) Mode(mode string) *EnvClass {
|
||||
this.mode = mode
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *EnvModel) All() (result map[string]any) {
|
||||
func (this *EnvClass) All() (result map[string]any) {
|
||||
|
||||
if this.mode == "toml" {
|
||||
return cast.ToStringMap(this.TomlAll())
|
||||
@@ -89,7 +89,7 @@ func (this *EnvModel) All() (result map[string]any) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *EnvModel) Get(key any, def ...any) (result any) {
|
||||
func (this *EnvClass) Get(key any, def ...any) (result any) {
|
||||
|
||||
if this.mode == "toml" {
|
||||
result = this.TomlAll()
|
||||
@@ -108,7 +108,7 @@ func (this *EnvModel) Get(key any, def ...any) (result any) {
|
||||
return item[cast.ToString(key)]
|
||||
}
|
||||
|
||||
func (this *EnvModel) TomlAll() (result any) {
|
||||
func (this *EnvClass) TomlAll() (result any) {
|
||||
|
||||
// 文件路径
|
||||
viper.SetConfigFile(this.path)
|
||||
|
@@ -6,12 +6,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Format *FormatStruct
|
||||
var Format *FormatClass
|
||||
|
||||
type FormatStruct struct{}
|
||||
type FormatClass struct{}
|
||||
|
||||
// Query 转 Query 格式
|
||||
func (this *FormatStruct) Query(data any) (result string) {
|
||||
func (this *FormatClass) Query(data any) (result string) {
|
||||
|
||||
body := cast.ToStringMap(data)
|
||||
|
||||
|
14
utils/get.go
14
utils/get.go
@@ -10,18 +10,18 @@ import (
|
||||
)
|
||||
|
||||
// Get - 获取
|
||||
var Get *GetStruct
|
||||
var Get *GetClass
|
||||
|
||||
type GetStruct struct{}
|
||||
type GetClass struct{}
|
||||
|
||||
// Type - 获取数据类型
|
||||
func (this *GetStruct) Type(value any) (result string) {
|
||||
func (this *GetClass) Type(value any) (result string) {
|
||||
result, _ = typeof(value)
|
||||
return result
|
||||
}
|
||||
|
||||
// Ip - 获取客户端IP
|
||||
func (this *GetStruct) Ip(key ...string) (result any) {
|
||||
func (this *GetClass) Ip(key ...string) (result any) {
|
||||
|
||||
type lock struct {
|
||||
Lock *sync.RWMutex
|
||||
@@ -72,7 +72,7 @@ func (this *GetStruct) Ip(key ...string) (result any) {
|
||||
}
|
||||
|
||||
// Mac - 获取本机MAC
|
||||
func (this *GetStruct) Mac() (result string) {
|
||||
func (this *GetClass) Mac() (result string) {
|
||||
|
||||
interfaces, err := net.Interfaces()
|
||||
|
||||
@@ -99,7 +99,7 @@ func (this *GetStruct) Mac() (result string) {
|
||||
}
|
||||
|
||||
// Pid - 获取进程ID
|
||||
func (this *GetStruct) Pid() (result int) {
|
||||
func (this *GetClass) Pid() (result int) {
|
||||
process, err := os.FindProcess(os.Getpid())
|
||||
if err != nil {
|
||||
return 0
|
||||
@@ -108,7 +108,7 @@ func (this *GetStruct) Pid() (result int) {
|
||||
}
|
||||
|
||||
// Pwd - 获取当前目录
|
||||
func (this *GetStruct) Pwd() (result string) {
|
||||
func (this *GetClass) Pwd() (result string) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
|
80
utils/is.go
80
utils/is.go
@@ -7,12 +7,12 @@ import (
|
||||
)
|
||||
|
||||
// Is - 是否为
|
||||
var Is *IsStruct
|
||||
var Is *IsClass
|
||||
|
||||
type IsStruct struct{}
|
||||
type IsClass struct{}
|
||||
|
||||
// Email - 是否为邮箱
|
||||
func (this *IsStruct) Email(email any) (ok bool) {
|
||||
func (this *IsClass) Email(email any) (ok bool) {
|
||||
if email == nil {
|
||||
return false
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func (this *IsStruct) Email(email any) (ok bool) {
|
||||
}
|
||||
|
||||
// Phone - 是否为手机号
|
||||
func (this *IsStruct) Phone(phone any) (ok bool) {
|
||||
func (this *IsClass) Phone(phone any) (ok bool) {
|
||||
if phone == nil {
|
||||
return false
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func (this *IsStruct) Phone(phone any) (ok bool) {
|
||||
}
|
||||
|
||||
// Mobile - 是否为手机号
|
||||
func (this *IsStruct) Mobile(value any) (ok bool) {
|
||||
func (this *IsClass) Mobile(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -36,13 +36,13 @@ func (this *IsStruct) Mobile(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Empty - 是否为空
|
||||
func (this *IsStruct) Empty(value any) (ok bool) {
|
||||
func (this *IsClass) Empty(value any) (ok bool) {
|
||||
_, empty := typeof(value)
|
||||
return empty
|
||||
}
|
||||
|
||||
// Domain - 是否为域名
|
||||
func (this *IsStruct) Domain(domain any) (ok bool) {
|
||||
func (this *IsClass) Domain(domain any) (ok bool) {
|
||||
if domain == nil {
|
||||
return false
|
||||
}
|
||||
@@ -50,17 +50,17 @@ func (this *IsStruct) Domain(domain any) (ok bool) {
|
||||
}
|
||||
|
||||
// True - 是否为真
|
||||
func (this *IsStruct) True(value any) (ok bool) {
|
||||
func (this *IsClass) True(value any) (ok bool) {
|
||||
return cast.ToBool(value)
|
||||
}
|
||||
|
||||
// False - 是否为假
|
||||
func (this *IsStruct) False(value any) (ok bool) {
|
||||
func (this *IsClass) False(value any) (ok bool) {
|
||||
return !cast.ToBool(value)
|
||||
}
|
||||
|
||||
// Number - 是否为数字
|
||||
func (this *IsStruct) Number(value any) (ok bool) {
|
||||
func (this *IsClass) Number(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (this *IsStruct) Number(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Float - 是否为浮点数
|
||||
func (this *IsStruct) Float(value any) (ok bool) {
|
||||
func (this *IsClass) Float(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -76,12 +76,12 @@ func (this *IsStruct) Float(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Bool - 是否为bool
|
||||
func (this *IsStruct) Bool(value any) (ok bool) {
|
||||
func (this *IsClass) Bool(value any) (ok bool) {
|
||||
return cast.ToBool(value)
|
||||
}
|
||||
|
||||
// Accepted - 验证某个字段是否为为 yes, on, 或是 1
|
||||
func (this *IsStruct) Accepted(value any) (ok bool) {
|
||||
func (this *IsClass) Accepted(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (this *IsStruct) Accepted(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Date - 是否为日期类型
|
||||
func (this *IsStruct) Date(date any) (ok bool) {
|
||||
func (this *IsClass) Date(date any) (ok bool) {
|
||||
if date == nil {
|
||||
return false
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func (this *IsStruct) Date(date any) (ok bool) {
|
||||
}
|
||||
|
||||
// Alpha - 只能包含字母
|
||||
func (this *IsStruct) Alpha(value any) (ok bool) {
|
||||
func (this *IsClass) Alpha(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (this *IsStruct) Alpha(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// AlphaNum - 只能包含字母和数字
|
||||
func (this *IsStruct) AlphaNum(value any) (ok bool) {
|
||||
func (this *IsClass) AlphaNum(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (this *IsStruct) AlphaNum(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// AlphaDash - 只能包含字母、数字和下划线_及破折号-
|
||||
func (this *IsStruct) AlphaDash(value any) (ok bool) {
|
||||
func (this *IsClass) AlphaDash(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (this *IsStruct) AlphaDash(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Chs - 是否为汉字
|
||||
func (this *IsStruct) Chs(value any) (ok bool) {
|
||||
func (this *IsClass) Chs(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (this *IsStruct) Chs(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// ChsAlpha - 只能是汉字、字母
|
||||
func (this *IsStruct) ChsAlpha(value any) (ok bool) {
|
||||
func (this *IsClass) ChsAlpha(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (this *IsStruct) ChsAlpha(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// ChsAlphaNum - 只能是汉字、字母和数字
|
||||
func (this *IsStruct) ChsAlphaNum(value any) (ok bool) {
|
||||
func (this *IsClass) ChsAlphaNum(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func (this *IsStruct) ChsAlphaNum(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// ChsDash - 只能是汉字、字母、数字和下划线_及破折号-
|
||||
func (this *IsStruct) ChsDash(value any) (ok bool) {
|
||||
func (this *IsClass) ChsDash(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (this *IsStruct) ChsDash(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Cntrl - 是否为控制字符 - (换行、缩进、空格)
|
||||
func (this *IsStruct) Cntrl(value any) (ok bool) {
|
||||
func (this *IsClass) Cntrl(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (this *IsStruct) Cntrl(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Graph - 是否为可见字符 - (除空格外的所有可打印字符)
|
||||
func (this *IsStruct) Graph(value any) (ok bool) {
|
||||
func (this *IsClass) Graph(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (this *IsStruct) Graph(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Lower - 是否为小写字母
|
||||
func (this *IsStruct) Lower(value any) (ok bool) {
|
||||
func (this *IsClass) Lower(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (this *IsStruct) Lower(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Upper - 是否为大写字母
|
||||
func (this *IsStruct) Upper(value any) (ok bool) {
|
||||
func (this *IsClass) Upper(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (this *IsStruct) Upper(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Space - 是否为空白字符 - (空格、制表符、换页符等)
|
||||
func (this *IsStruct) Space(value any) (ok bool) {
|
||||
func (this *IsClass) Space(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func (this *IsStruct) Space(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Xdigit - 是否为十六进制字符 - (0-9、a-f、A-F)
|
||||
func (this *IsStruct) Xdigit(value any) (ok bool) {
|
||||
func (this *IsClass) Xdigit(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func (this *IsStruct) Xdigit(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// ActiveUrl - 是否为有效的域名或者IP
|
||||
func (this *IsStruct) ActiveUrl(value any) (ok bool) {
|
||||
func (this *IsClass) ActiveUrl(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func (this *IsStruct) ActiveUrl(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Ip - 是否为IP
|
||||
func (this *IsStruct) Ip(ip any) (ok bool) {
|
||||
func (this *IsClass) Ip(ip any) (ok bool) {
|
||||
if ip == nil {
|
||||
return false
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func (this *IsStruct) Ip(ip any) (ok bool) {
|
||||
}
|
||||
|
||||
// Url - 是否为URL
|
||||
func (this *IsStruct) Url(url any) (ok bool) {
|
||||
func (this *IsClass) Url(url any) (ok bool) {
|
||||
if url == nil {
|
||||
return false
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func (this *IsStruct) Url(url any) (ok bool) {
|
||||
}
|
||||
|
||||
// IdCard - 是否为有效的身份证号码
|
||||
func (this *IsStruct) IdCard(value any) (ok bool) {
|
||||
func (this *IsClass) IdCard(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func (this *IsStruct) IdCard(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// MacAddr - 是否为有效的MAC地址
|
||||
func (this *IsStruct) MacAddr(value any) (ok bool) {
|
||||
func (this *IsClass) MacAddr(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func (this *IsStruct) MacAddr(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Zip - 是否为有效的邮政编码
|
||||
func (this *IsStruct) Zip(value any) (ok bool) {
|
||||
func (this *IsClass) Zip(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (this *IsStruct) Zip(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// String - 是否为字符串
|
||||
func (this *IsStruct) String(value any) (ok bool) {
|
||||
func (this *IsClass) String(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func (this *IsStruct) String(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Slice - 是否为切片
|
||||
func (this *IsStruct) Slice(value any) (ok bool) {
|
||||
func (this *IsClass) Slice(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func (this *IsStruct) Slice(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Array - 是否为数组
|
||||
func (this *IsStruct) Array(value any) (ok bool) {
|
||||
func (this *IsClass) Array(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (this *IsStruct) Array(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// JsonString - 是否为json字符串
|
||||
func (this *IsStruct) JsonString(value any) (ok bool) {
|
||||
func (this *IsClass) JsonString(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (this *IsStruct) JsonString(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// Map - 是否为map
|
||||
func (this *IsStruct) Map(value any) (ok bool) {
|
||||
func (this *IsClass) Map(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -289,7 +289,7 @@ func (this *IsStruct) Map(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// SliceSlice - 是否为二维切片
|
||||
func (this *IsStruct) SliceSlice(value any) (ok bool) {
|
||||
func (this *IsClass) SliceSlice(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
@@ -297,7 +297,7 @@ func (this *IsStruct) SliceSlice(value any) (ok bool) {
|
||||
}
|
||||
|
||||
// MapAny - 是否为[]map[string]any
|
||||
func (this *IsStruct) MapAny(value any) (ok bool) {
|
||||
func (this *IsClass) MapAny(value any) (ok bool) {
|
||||
if value == nil {
|
||||
return false
|
||||
}
|
||||
|
@@ -10,34 +10,34 @@ import (
|
||||
)
|
||||
|
||||
// Json - JSON 处理
|
||||
var Json *JsonStruct
|
||||
var Json *JsonClass
|
||||
|
||||
type JsonStruct struct{}
|
||||
type JsonClass struct{}
|
||||
|
||||
// Valid - 验证JSON数据
|
||||
func (this *JsonStruct) Valid(data any) (result bool) {
|
||||
func (this *JsonClass) Valid(data any) (result bool) {
|
||||
return json.Valid([]byte(cast.ToString(data)))
|
||||
}
|
||||
|
||||
// Encode 编码
|
||||
func (this *JsonStruct) Encode(data any) (result string) {
|
||||
func (this *JsonClass) Encode(data any) (result string) {
|
||||
text, err := json.Marshal(data)
|
||||
return Ternary(err != nil, "", string(text))
|
||||
}
|
||||
|
||||
// Decode 解码
|
||||
func (this *JsonStruct) Decode(data any) (result any) {
|
||||
func (this *JsonClass) Decode(data any) (result any) {
|
||||
err := json.Unmarshal([]byte(cast.ToString(data)), &result)
|
||||
return Ternary(err != nil, nil, result)
|
||||
}
|
||||
|
||||
// Unmarshal 解码
|
||||
func (this *JsonStruct) Unmarshal(data []byte, result any) (err error) {
|
||||
func (this *JsonClass) Unmarshal(data []byte, result any) (err error) {
|
||||
return JSON.Unmarshal(data, result)
|
||||
}
|
||||
|
||||
// Get 获取json中的值 - 支持多级
|
||||
func (this *JsonStruct) Get(jsonString any, key any) (result any, err error) {
|
||||
func (this *JsonClass) Get(jsonString any, key any) (result any, err error) {
|
||||
|
||||
if err := json.Unmarshal([]byte(cast.ToString(jsonString)), &result); err != nil {
|
||||
return nil, err
|
||||
@@ -61,7 +61,7 @@ func (this *JsonStruct) Get(jsonString any, key any) (result any, err error) {
|
||||
}
|
||||
|
||||
// String map转json字符串
|
||||
func (this *JsonStruct) String(data any) (result string) {
|
||||
func (this *JsonClass) String(data any) (result string) {
|
||||
|
||||
item := cast.ToStringMap(data)
|
||||
|
||||
|
@@ -5,16 +5,16 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type LangModel struct {
|
||||
type LangClass struct {
|
||||
Directory string // 语言包目录
|
||||
Lang string // 当前语言
|
||||
Mode string // 文件类型
|
||||
}
|
||||
|
||||
// Lang 实例化
|
||||
func Lang(model ...LangModel) *LangModel {
|
||||
func Lang(model ...LangClass) *LangClass {
|
||||
|
||||
item := new(LangModel)
|
||||
item := new(LangClass)
|
||||
|
||||
// 合并参数
|
||||
if len(model) > 0 {
|
||||
@@ -29,7 +29,7 @@ func Lang(model ...LangModel) *LangModel {
|
||||
return item
|
||||
}
|
||||
|
||||
func (this *LangModel) Value(key any, args ...any) (result any) {
|
||||
func (this *LangClass) Value(key any, args ...any) (result any) {
|
||||
|
||||
// 读取语言包
|
||||
bytes := File().Byte(this.Directory + this.Lang + "." + this.Mode)
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Mime *MimeStruct
|
||||
var Mime *MimeClass
|
||||
|
||||
type MimeStruct struct{}
|
||||
type MimeClass struct{}
|
||||
|
||||
var MimeMap = map[string]string{
|
||||
"js": "application/javascript",
|
||||
@@ -42,7 +42,7 @@ var MimeMap = map[string]string{
|
||||
}
|
||||
|
||||
// Type 获取后缀对应的 mime
|
||||
func (this *MimeStruct) Type(suffix any) (mime string) {
|
||||
func (this *MimeClass) Type(suffix any) (mime string) {
|
||||
// 获取后缀
|
||||
suffix = strings.ToLower(cast.ToString(suffix))
|
||||
// 取出 . 后面的内容
|
||||
|
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
// Net - 网络
|
||||
var Net *NetStruct
|
||||
var Net *NetClass
|
||||
|
||||
type NetStruct struct{}
|
||||
type NetClass struct {}
|
||||
|
||||
func (this *NetStruct) Tcping(host any, opts ...map[string]any) (ok bool, detail []map[string]any) {
|
||||
func (this *NetClass) Tcping(host any, opts ...map[string]any) (ok bool, detail []map[string]any) {
|
||||
|
||||
if len(opts) == 0 {
|
||||
opts = append(opts, map[string]any{
|
||||
|
@@ -37,13 +37,13 @@ func (this *wrLock) has(key string) (ok bool) {
|
||||
}
|
||||
|
||||
// Parse - 解析
|
||||
var Parse *ParseStruct
|
||||
var Parse *ParseClass
|
||||
|
||||
type ParseStruct struct{}
|
||||
type ParseClass struct {}
|
||||
|
||||
// ParamsBefore - 解析参数
|
||||
// 把 Content-Type = application/x-www-form-urlencoded 的参数解析成 object.deep.age = 10 的格式
|
||||
func (this *ParseStruct) ParamsBefore(params url.Values) (result map[string]any) {
|
||||
func (this *ParseClass) ParamsBefore(params url.Values) (result map[string]any) {
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wr := wrLock{
|
||||
@@ -123,7 +123,7 @@ func (this *ParseStruct) ParamsBefore(params url.Values) (result map[string]any)
|
||||
|
||||
// Params - 解析参数
|
||||
// 把 Content-Type = application/x-www-form-urlencoded 的参数解析成 map[string]any
|
||||
func (this *ParseStruct) Params(params map[string]any) (result map[string]any) {
|
||||
func (this *ParseClass) Params(params map[string]any) (result map[string]any) {
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wr := wrLock{
|
||||
@@ -174,7 +174,7 @@ func (this *ParseStruct) Params(params map[string]any) (result map[string]any) {
|
||||
}
|
||||
|
||||
// Domain - 解析域名
|
||||
func (this *ParseStruct) Domain(value any) (domain string) {
|
||||
func (this *ParseClass) Domain(value any) (domain string) {
|
||||
URL, err := url.Parse(cast.ToString(value))
|
||||
if err != nil {
|
||||
return ""
|
||||
|
@@ -8,12 +8,12 @@ import (
|
||||
)
|
||||
|
||||
// Rand - 随机数
|
||||
var Rand *RandStruct
|
||||
var Rand *RandClass
|
||||
|
||||
type RandStruct struct{}
|
||||
type RandClass struct {}
|
||||
|
||||
// Number - 生成指定长度的随机数
|
||||
func (this *RandStruct) Number(length any) (result string) {
|
||||
func (this *RandClass) Number(length any) (result string) {
|
||||
|
||||
mac := Hash.Sum32(Get.Mac())
|
||||
pid := Get.Pid()
|
||||
@@ -44,7 +44,7 @@ func (this *RandStruct) Number(length any) (result string) {
|
||||
}
|
||||
|
||||
// String - 生成随机字符串
|
||||
func (this *RandStruct) String(length any, chars ...string) (result string) {
|
||||
func (this *RandClass) String(length any, chars ...string) (result string) {
|
||||
|
||||
var charset string
|
||||
|
||||
@@ -63,8 +63,32 @@ func (this *RandStruct) String(length any, chars ...string) (result string) {
|
||||
return string(item)
|
||||
}
|
||||
|
||||
// Code - 生成随机验证码
|
||||
// number:数字, letter:字母, mix:混合
|
||||
func (this *RandClass) Code(length any, mode ...string) (result string) {
|
||||
|
||||
var charset string
|
||||
|
||||
if Is.Empty(mode) {
|
||||
charset = "number"
|
||||
} else {
|
||||
charset = mode[0]
|
||||
}
|
||||
|
||||
switch charset {
|
||||
case "number":
|
||||
return this.Number(length)
|
||||
case "letter":
|
||||
return this.String(length, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
case "mix":
|
||||
return this.String(length, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
default:
|
||||
return this.Number(length)
|
||||
}
|
||||
}
|
||||
|
||||
// Int - 生成随机整数
|
||||
func (this *RandStruct) Int(max any, min ...any) (result int) {
|
||||
func (this *RandClass) Int(max any, min ...any) (result int) {
|
||||
if Is.Empty(min) {
|
||||
min = []any{0}
|
||||
}
|
||||
@@ -80,7 +104,7 @@ func (this *RandStruct) Int(max any, min ...any) (result int) {
|
||||
}
|
||||
|
||||
// Slice - 返回随机的指定长度的切片
|
||||
func (this *RandStruct) Slice(slice []any, limit any) (result []any) {
|
||||
func (this *RandClass) Slice(slice []any, limit any) (result []any) {
|
||||
|
||||
// 如果切片为空,直接返回
|
||||
if len(slice) == 0 {
|
||||
@@ -113,7 +137,7 @@ func (this *RandStruct) Slice(slice []any, limit any) (result []any) {
|
||||
}
|
||||
|
||||
// MapSlice - 打乱切片顺序
|
||||
func (this *RandStruct) MapSlice(slice []map[string]any) (result []map[string]any) {
|
||||
func (this *RandClass) MapSlice(slice []map[string]any) (result []map[string]any) {
|
||||
|
||||
// 如果切片为空,直接返回
|
||||
if len(slice) == 0 {
|
||||
|
@@ -6,12 +6,12 @@ import (
|
||||
)
|
||||
|
||||
// Struct - 操作结构体
|
||||
var Struct *StructStruct
|
||||
var Struct *StructClass
|
||||
|
||||
type StructStruct struct{}
|
||||
type StructClass struct {}
|
||||
|
||||
// Set - 动态给结构体赋值
|
||||
func (this *StructStruct) Set(obj any, key string, val any) {
|
||||
func (this *StructClass) Set(obj any, key string, val any) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -43,7 +43,7 @@ func (this *StructStruct) Set(obj any, key string, val any) {
|
||||
}
|
||||
|
||||
// Get - 动态获取结构体的值
|
||||
func (this *StructStruct) Get(obj any, key string) (result any) {
|
||||
func (this *StructClass) Get(obj any, key string) (result any) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -64,7 +64,7 @@ func (this *StructStruct) Get(obj any, key string) (result any) {
|
||||
}
|
||||
|
||||
// Del - 删除结构体的字段
|
||||
func (this *StructStruct) Del(obj any, key string) {
|
||||
func (this *StructClass) Del(obj any, key string) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -84,7 +84,7 @@ func (this *StructStruct) Del(obj any, key string) {
|
||||
}
|
||||
|
||||
// Has - 判断结构体是否存在某个字段
|
||||
func (this *StructStruct) Has(obj any, key string) (ok bool) {
|
||||
func (this *StructClass) Has(obj any, key string) (ok bool) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -104,7 +104,7 @@ func (this *StructStruct) Has(obj any, key string) (ok bool) {
|
||||
}
|
||||
|
||||
// Keys - 获取结构体的字段
|
||||
func (this *StructStruct) Keys(obj any) (slice []string) {
|
||||
func (this *StructClass) Keys(obj any) (slice []string) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -124,7 +124,7 @@ func (this *StructStruct) Keys(obj any) (slice []string) {
|
||||
}
|
||||
|
||||
// Values - 获取结构体的值
|
||||
func (this *StructStruct) Values(obj any) (slice []any) {
|
||||
func (this *StructClass) Values(obj any) (slice []any) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 定义一个切片
|
||||
@@ -138,14 +138,14 @@ func (this *StructStruct) Values(obj any) (slice []any) {
|
||||
}
|
||||
|
||||
// Len - 获取结构体的长度
|
||||
func (this *StructStruct) Len(obj any) (length int) {
|
||||
func (this *StructClass) Len(obj any) (length int) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
return value.NumField()
|
||||
}
|
||||
|
||||
// Map - 将结构体转换为map
|
||||
func (this *StructStruct) Map(obj any) (result map[string]any) {
|
||||
func (this *StructClass) Map(obj any) (result map[string]any) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 获取结构体的类型
|
||||
@@ -165,7 +165,7 @@ func (this *StructStruct) Map(obj any) (result map[string]any) {
|
||||
}
|
||||
|
||||
// Slice - 将结构体转换为切片
|
||||
func (this *StructStruct) Slice(obj any) (slice []any) {
|
||||
func (this *StructClass) Slice(obj any) (slice []any) {
|
||||
// 获取结构体的值
|
||||
value := reflect.ValueOf(obj).Elem()
|
||||
// 定义一个切片
|
||||
@@ -179,11 +179,11 @@ func (this *StructStruct) Slice(obj any) (slice []any) {
|
||||
}
|
||||
|
||||
// ToStringMap - 将结构体转换为map[string]any
|
||||
func (this *StructStruct) ToStringMap(obj any) (result map[string]any) {
|
||||
func (this *StructClass) ToStringMap(obj any) (result map[string]any) {
|
||||
return cast.ToStringMap(Json.Encode(obj))
|
||||
}
|
||||
|
||||
// ToAsciiString - 将结构体转换为ASCII字符串
|
||||
func (this *StructStruct) ToAsciiString(obj any) (result string) {
|
||||
func (this *StructClass) ToAsciiString(obj any) (result string) {
|
||||
return Ascii.ToString(this.ToStringMap(obj), true)
|
||||
}
|
@@ -6,12 +6,12 @@ import (
|
||||
)
|
||||
|
||||
// Unity - 统一规范化
|
||||
var Unity *UnityStruct
|
||||
var Unity *UnityClass
|
||||
|
||||
type UnityStruct struct{}
|
||||
type UnityClass struct{}
|
||||
|
||||
// Ids 参数归一化
|
||||
func (this *UnityStruct) Ids(param ...any) (ids []any) {
|
||||
func (this *UnityClass) Ids(param ...any) (ids []any) {
|
||||
|
||||
fn := func(param any) (ids []any) {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (this *UnityStruct) Ids(param ...any) (ids []any) {
|
||||
}
|
||||
|
||||
// Keys 参数归一化
|
||||
func (this *UnityStruct) Keys(param any, reg ...any) (keys []any) {
|
||||
func (this *UnityClass) Keys(param any, reg ...any) (keys []any) {
|
||||
|
||||
// 正则表达式
|
||||
var regex string
|
||||
|
12
utils/url.go
12
utils/url.go
@@ -6,13 +6,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Url = &UrlStruct{}
|
||||
var Url = &UrlClass{}
|
||||
|
||||
type UrlStruct struct {
|
||||
type UrlClass struct {
|
||||
}
|
||||
|
||||
// Encoded - 将 map 编码为 URL 查询字符串 - x-www-form-urlencoded
|
||||
func (this *UrlStruct) Encoded(params map[string]any) string {
|
||||
func (this *UrlClass) Encoded(params map[string]any) string {
|
||||
|
||||
var parts []string
|
||||
|
||||
@@ -24,7 +24,7 @@ func (this *UrlStruct) Encoded(params map[string]any) string {
|
||||
}
|
||||
|
||||
// EncodedKeys - 获取 URL 查询字符串的键
|
||||
func (this *UrlStruct) EncodedKeys(params map[string]any) []string {
|
||||
func (this *UrlClass) EncodedKeys(params map[string]any) []string {
|
||||
|
||||
encoded := this.Encoded(params)
|
||||
// & 分隔数组,字符串转数组
|
||||
@@ -38,7 +38,7 @@ func (this *UrlStruct) EncodedKeys(params map[string]any) []string {
|
||||
}
|
||||
|
||||
// build - 构建 URL 查询字符串
|
||||
func (this *UrlStruct) build(key string, value any) []string {
|
||||
func (this *UrlClass) build(key string, value any) []string {
|
||||
|
||||
var parts []string
|
||||
|
||||
@@ -69,7 +69,7 @@ func (this *UrlStruct) build(key string, value any) []string {
|
||||
}
|
||||
|
||||
// stringify - 将任意类型转换为字符串
|
||||
func (this *UrlStruct) stringify(value any) string {
|
||||
func (this *UrlClass) stringify(value any) string {
|
||||
|
||||
item := reflect.ValueOf(value)
|
||||
|
||||
|
@@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
// Version - 版本
|
||||
var Version *VersionStruct
|
||||
var Version *VersionClass
|
||||
|
||||
type VersionStruct struct{}
|
||||
type VersionClass struct{}
|
||||
|
||||
// Go - 获取当前go版本号
|
||||
func (this *VersionStruct) Go() (result string) {
|
||||
func (this *VersionClass) Go() (result string) {
|
||||
return strings.Replace(runtime.Version(), "go", "", -1)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func (this *VersionStruct) Go() (result string) {
|
||||
* @example:
|
||||
* utils.Version.Compare("1.2.0", "1.0.0") // 1
|
||||
*/
|
||||
func (this *VersionStruct) Compare(v1, v2 any) (result int) {
|
||||
func (this *VersionClass) Compare(v1, v2 any) (result int) {
|
||||
|
||||
rule := regexp.MustCompile(`\d+`)
|
||||
v1Arr := rule.FindAllString(cast.ToString(v1), -1)
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type ViperModel struct {
|
||||
type ViperClass struct {
|
||||
// 配置文件路径
|
||||
Path string
|
||||
// 配置文件类型
|
||||
@@ -26,9 +26,9 @@ type ViperResponse struct {
|
||||
Viper *viper.Viper
|
||||
}
|
||||
|
||||
func Viper(model ...ViperModel) *ViperModel {
|
||||
func Viper(model ...ViperClass) *ViperClass {
|
||||
|
||||
var item *ViperModel
|
||||
var item *ViperClass
|
||||
|
||||
if len(model) > 0 {
|
||||
item = &model[0]
|
||||
@@ -37,22 +37,22 @@ func Viper(model ...ViperModel) *ViperModel {
|
||||
return item
|
||||
}
|
||||
|
||||
func (this *ViperModel) SetPath(path string) *ViperModel {
|
||||
func (this *ViperClass) SetPath(path string) *ViperClass {
|
||||
this.Path = path
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ViperModel) SetMode(mode string) *ViperModel {
|
||||
func (this *ViperClass) SetMode(mode string) *ViperClass {
|
||||
this.Mode = mode
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ViperModel) SetName(name string) *ViperModel {
|
||||
func (this *ViperClass) SetName(name string) *ViperClass {
|
||||
this.Name = name
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ViperModel) Read() (result ViperResponse) {
|
||||
func (this *ViperClass) Read() (result ViperResponse) {
|
||||
|
||||
item := viper.New()
|
||||
|
||||
|
Reference in New Issue
Block a user