Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# helays/utils

通用 Go 工具包集合 —— 一组实用、模块化的基础库,用于加速后端服务和工具类开发。模块以 `github.com/helays/utils/v2` 作为 module 前缀导入,包含文件/IO 工具、模板助手、HTTP 层辅助、文件存储驱动、数据库辅助、规则验证引擎、锁定策略、安全工具与日志封装等。
通用 Go 工具包集合 —— 一组实用、模块化的基础库,用于加速后端服务和工具类开发。模块以 `helay.net/go/utils/v3` 作为 module 前缀导入,包含文件/IO 工具、模板助手、HTTP 层辅助、文件存储驱动、数据库辅助、规则验证引擎、锁定策略、安全工具与日志封装等。

---

Expand All @@ -9,16 +9,16 @@
1. **安装(模块导入):**

```bash
go get github.com/helays/utils/v2
go get helay.net/go/utils/v3
```

2. **典型导入示例:**

```go
import (
"github.com/helays/utils/v2/tools"
"github.com/helays/utils/v2/template/template_engine"
"github.com/helays/utils/v2/rule-engine/validator"
"helay.net/go/utils/v3/tools"
"helay.net/go/utils/v3/template/template_engine"
"helay.net/go/utils/v3/rule-engine/validator"
)
```

Expand Down Expand Up @@ -51,7 +51,7 @@ msg, ok := rule.Validate(map[string]any{"age": 20})

1. **tools — 通用辅助工具**

- 包路径:`github.com/helays/utils/v2/tools`
- 包路径:`helay.net/go/utils/v3/tools`

- 功能:字符串与命名转换、文件读写、IO 辅助、map/切片工具、环形缓冲索引、深拷贝等。

Expand All @@ -63,7 +63,7 @@ msg, ok := rule.Validate(map[string]any{"age": 20})

2. **net/http — HTTP 层工具与中间件**

- 包路径:`github.com/helays/utils/v2/net/http`(及其子包)
- 包路径:`helay.net/go/utils/v3/net/http`(及其子包)

- 功能:统一响应(response)、路由处理、http server 支持、session、mime、route 中间件(日志/metrics)等。

Expand All @@ -74,7 +74,7 @@ msg, ok := rule.Validate(map[string]any{"age": 20})

3. **template/template_engine — 模板内置函数**

- 包路径:`github.com/helays/utils/v2/template/template_engine`
- 包路径:`helay.net/go/utils/v3/template/template_engine`

- 功能:为 `html/template` 提供内置函数(时间、格式化、链接生成、dict、循环等)。

Expand All @@ -86,9 +86,9 @@ msg, ok := rule.Validate(map[string]any{"age": 20})
4. **file/filesaver & db/fileSaver — 文件存储抽象与驱动**

- 包路径:
- 抽象:`github.com/helays/utils/v2/file/filesaver`
- 本地驱动:`github.com/helays/utils/v2/file/filesaver/localfile`
- MinIO 驱动:`github.com/helays/utils/v2/db/fileSaver/minio`
- 抽象:`helay.net/go/utils/v3/file/filesaver`
- 本地驱动:`helay.net/go/utils/v3/file/filesaver/localfile`
- MinIO 驱动:`helay.net/go/utils/v3/db/fileSaver/minio`

- 功能:统一文件写入/读取/列举/删除接口,支持本地、FTP、SFTP、HDFS、MinIO 等后端。

Expand All @@ -97,7 +97,7 @@ msg, ok := rule.Validate(map[string]any{"age": 20})

5. **db — 数据库辅助与查询构造器**

- 包路径:`github.com/helays/utils/v2/db`,查询构造器在 `db/query`
- 包路径:`helay.net/go/utils/v3/db`,查询构造器在 `db/query`

- 功能:DSN 构建(MySQL/Postgres/SQLite)、查询构造器到 GORM clause 的转换、字段解析工具。

Expand All @@ -106,14 +106,14 @@ msg, ok := rule.Validate(map[string]any{"age": 20})

6. **db/localredis — 本地 Redis 适配(测试替代)**

- 包路径:`github.com/helays/utils/v2/db/localredis`
- 包路径:`helay.net/go/utils/v3/db/localredis`

- 说明:提供本地实现以便在无 Redis 环境或测试中替代真实 redis 客户端。注意:部分方法为占位实现,生产使用前请确认完整性。


7. **rule-engine/validator — 规则验证引擎**

- 包路径:`github.com/helays/utils/v2/rule-engine/validator`
- 包路径:`helay.net/go/utils/v3/rule-engine/validator`

- 功能:支持数据类型、长度、格式、内容与高级表达式验证;支持 AND/OR 逻辑组合、通配符字段、CEL/Go/JSONLogic 等表达式类型;内置中文错误提示。

Expand All @@ -126,26 +126,26 @@ msg, ok := rule.Validate(map[string]any{"age": 20})
- lockpolicy(锁定策略管理,session/ip/user,多层锁定与升级链)
- cors(CORS 策略与预检处理)

- 包路径:`github.com/helays/utils/v2/security/...`
- 包路径:`helay.net/go/utils/v3/security/...`


9. **logger — 日志实现**

- 包路径:`github.com/helays/utils/v2/logger`(含 `ulogs`、`zaploger`)
- 包路径:`helay.net/go/utils/v3/logger`(含 `ulogs`、`zaploger`)

- 功能:日志记录、文件滚动(结合 lumberjack)、HTTP 请求日志中间件等。


10. **crypto — 加密工具**

- 包路径:`github.com/helays/utils/v2/crypto/aes`
- 包路径:`helay.net/go/utils/v3/crypto/aes`

- 功能:AES CBC 简单加解密(包含 padding/unpadding,适用于简单场景)。


11. **config — 配置与正则常量**

- 包路径:`github.com/helays/utils/v2/config`
- 包路径:`helay.net/go/utils/v3/config`

- 功能:常用正则(手机号、邮箱、页面解析)、YAML 加载器(支持 include 机制)。

Expand Down
2 changes: 1 addition & 1 deletion close/esClose/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package esClose

import (
"github.com/elastic/go-elasticsearch/v8/esapi"
"github.com/helays/utils/v2/close/vclose"
"helay.net/go/utils/v3/close/vclose"
)

// CloseResp 关闭esapi.Response
Expand Down
2 changes: 1 addition & 1 deletion close/gormClose/close.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gormClose

import (
"github.com/helays/utils/v2/close/vclose"
"gorm.io/gorm"
"helay.net/go/utils/v3/close/vclose"
)

func Close(db *gorm.DB) {
Expand Down
2 changes: 1 addition & 1 deletion close/kafkaClose/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kafkaClose

import (
"github.com/IBM/sarama"
"github.com/helays/utils/v2/logger/ulogs"
"helay.net/go/utils/v3/logger/ulogs"
)

// CloseKafkaPartition 关闭分区
Expand Down
2 changes: 1 addition & 1 deletion close/test/clsoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/helays/utils/v2/close/vclose"
"helay.net/go/utils/v3/close/vclose"
"os"
)

Expand Down
4 changes: 2 additions & 2 deletions cluster/etcd/electMaster/elect.master.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package electMaster

import (
"context"
"github.com/helays/utils/v2/close/vclose"
"github.com/helays/utils/v2/logger/ulogs"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
"helay.net/go/utils/v3/close/vclose"
"helay.net/go/utils/v3/logger/ulogs"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion cluster/nacos/electMaster/elect.master.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package electMaster

import (
"fmt"
"github.com/helays/utils/v2/logger/ulogs"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/v2/model"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"helay.net/go/utils/v3/logger/ulogs"
"sort"
"time"
)
Expand Down
4 changes: 2 additions & 2 deletions cluster/zookeeper/electMaster/elect.master.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package electMaster
import (
"errors"
"github.com/go-zookeeper/zk"
"github.com/helays/utils/v2/db/zookeeper"
"github.com/helays/utils/v2/logger/ulogs"
"helay.net/go/utils/v3/db/zookeeper"
"helay.net/go/utils/v3/logger/ulogs"
"path"
"sort"
"strings"
Expand Down
4 changes: 2 additions & 2 deletions compress/zipkit/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"path/filepath"

"github.com/helays/utils/v2/close/osClose"
"github.com/helays/utils/v2/close/vclose"
"helay.net/go/utils/v3/close/osClose"
"helay.net/go/utils/v3/close/vclose"
)

// CompressFileToZip 将多个文件压缩为ZIP文件
Expand Down
2 changes: 1 addition & 1 deletion config/cfg-proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/url"
"strings"

_ "github.com/helays/utils/v2/net/http/http-proxy"
"github.com/pkg/errors"
"golang.org/x/net/proxy"
_ "helay.net/go/utils/v3/net/http/http-proxy"
)

type ProxyTypes string
Expand Down
10 changes: 5 additions & 5 deletions config/loadAuto/auto.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package loadAuto

import (
"github.com/helays/utils/v2/config"
loadIni2 "github.com/helays/utils/v2/config/loadIni"
loadJson2 "github.com/helays/utils/v2/config/loadJson"
"github.com/helays/utils/v2/config/loadYaml"
"github.com/helays/utils/v2/logger/ulogs"
"helay.net/go/utils/v3/config"
loadIni2 "helay.net/go/utils/v3/config/loadIni"
loadJson2 "helay.net/go/utils/v3/config/loadJson"
"helay.net/go/utils/v3/config/loadYaml"
"helay.net/go/utils/v3/logger/ulogs"
"path/filepath"
)

Expand Down
6 changes: 3 additions & 3 deletions config/loadIni/load.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package loadIni

import (
"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/logger/ulogs"
"github.com/helays/utils/v2/tools"
"gopkg.in/ini.v1"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/logger/ulogs"
"helay.net/go/utils/v3/tools"
)

func LoadIni(i any) {
Expand Down
8 changes: 4 additions & 4 deletions config/loadJson/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package loadJson
import (
"encoding/json"
"fmt"
"github.com/helays/utils/v2/close/osClose"
"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/logger/ulogs"
"github.com/helays/utils/v2/tools"
"helay.net/go/utils/v3/close/osClose"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/logger/ulogs"
"helay.net/go/utils/v3/tools"
"os"
)

Expand Down
10 changes: 5 additions & 5 deletions config/loadYaml/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"os"
"path/filepath"

"github.com/helays/utils/v2/close/osClose"
"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/logger/ulogs"
"github.com/helays/utils/v2/tools"
"github.com/helays/utils/v2/tools/fileinclude"
"gopkg.in/yaml.v3"
"helay.net/go/utils/v3/close/osClose"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/logger/ulogs"
"helay.net/go/utils/v3/tools"
"helay.net/go/utils/v3/tools/fileinclude"
)

func LoadYaml(i any) {
Expand Down
6 changes: 3 additions & 3 deletions config/parseCmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"os"

"github.com/helays/utils/v2"
"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/logger/ulogs"
"helay.net/go/utils/v3"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/logger/ulogs"
)

// Parseparams 解析启动参数
Expand Down
4 changes: 2 additions & 2 deletions crypto/rsa/Rsa.3Des.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"github.com/helays/utils/v2/crypto/sm4"
"github.com/helays/utils/v2/logger/ulogs"
"helay.net/go/utils/v3/crypto/sm4"
"helay.net/go/utils/v3/logger/ulogs"
"io/ioutil"
)

Expand Down
4 changes: 2 additions & 2 deletions crypto/rsa/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"encoding/pem"
"errors"

"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/crypto/sha256"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/crypto/sha256"
)

// RsaVerify 签名验证,用公钥进行验证
Expand Down
2 changes: 1 addition & 1 deletion crypto/tls.config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"os"

"github.com/helays/utils/v2/tools"
"helay.net/go/utils/v3/tools"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion crypto/xxhashkit/xxhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xxhashkit

import (
"github.com/cespare/xxhash/v2"
"github.com/helays/utils/v2/tools"
"helay.net/go/utils/v3/tools"
)

func XXHashString(s string) string {
Expand Down
4 changes: 2 additions & 2 deletions dataType/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"database/sql/driver"
"encoding/json"

"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/tools"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/tools"
)

// Bool 注意当使用这个类型时,在定义模型时,默认值需要带上括号。不然pg数据库会报错。
Expand Down
4 changes: 2 additions & 2 deletions dataType/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"strconv"
"strings"

"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/tools"
"golang.org/x/exp/constraints"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/tools"
)

func BlobDbDataType(db *gorm.DB, _ *schema.Field) string {
Expand Down
2 changes: 1 addition & 1 deletion dataType/content_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http"
"strings"

"github.com/helays/utils/v2/config"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"helay.net/go/utils/v3/config"
)

// ContentType 表示检测到的内容类型
Expand Down
6 changes: 3 additions & 3 deletions dataType/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"strings"
"time"

"github.com/helays/utils/v2/config"
"github.com/helays/utils/v2/rule-engine/formatter"
"github.com/helays/utils/v2/tools"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"helay.net/go/utils/v3/config"
"helay.net/go/utils/v3/rule-engine/formatter"
"helay.net/go/utils/v3/tools"
)

type CustomDate struct {
Expand Down
Loading