From f9c705c6962084244db71e191496d0af5c7030f5 Mon Sep 17 00:00:00 2001
From: xuchang <574616156@qq.com>
Date: Fri, 28 Jul 2023 18:08:19 +0800
Subject: [PATCH 1/4] =?UTF-8?q?v1.0.5=20http=E3=80=81config=E3=80=81json?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 162 ++++++++++++++++++-
base/response.go | 15 ++
example/compress_test.go | 2 +-
example/config_test.go | 2 +-
example/http_test.go | 180 ++++++++++-----------
example/json_test.go | 28 ++++
example/testdata/a.txt | 1 +
go.mod | 5 +
go.sum | 14 ++
{compress => io/compress}/compress.go | 0
{file => io}/excel/excel.go | 0
{file => io/files}/file.go | 2 +-
io/json/format.go | 23 +++
io/xml/xml.go | 1 +
net/http/http.go | 218 +++++++++++++++++++++++---
15 files changed, 525 insertions(+), 128 deletions(-)
create mode 100644 example/json_test.go
create mode 100644 example/testdata/a.txt
rename {compress => io/compress}/compress.go (100%)
rename {file => io}/excel/excel.go (100%)
rename {file => io/files}/file.go (73%)
create mode 100644 io/json/format.go
create mode 100644 io/xml/xml.go
diff --git a/README.md b/README.md
index 0aaa1c9..03b8ea1 100644
--- a/README.md
+++ b/README.md
@@ -35,9 +35,115 @@ go get -u github.com/wegoteam/wepkg@latest
- 响应结构体
- 分页
-### net/http
+### net
+- http client的封装(get post put...)
+- rpc
+- websocket
+- tcp
+- udp
+- grpc
+- mqtt
+- nats
+#### net/http
封装http请求的客户端
+```go
+func TestDefaultClientPOST(t *testing.T) {
+ client := http.BuildDefaultClient()
+ var res string
+ resp, err := client.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(`{"roleName":""}`).
+ SetResult(res).
+ Post("http://localhost:18080/weflow/role/list")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", resp)
+ fmt.Println("Response Info:", res)
+}
+
+type Response[T any] struct {
+ Code int `json:"code"` // 0:成功,其他:失败
+ Msg string `json:"msg"` // 错误信息
+ Data T `json:"data"` // 数据
+}
+
+type RoleInfoResult struct {
+ ID int64 `json:"id"` // 唯一id
+ RoleID string `json:"roleID"` // 角色id
+ ParentID string `json:"parentID"` // 角色父id
+ RoleName string `json:"roleName"` // 角色名称
+ Status int32 `json:"status"` // 状态【1:未启用;2:已启用;3:锁定;】
+ Remark string `json:"remark"` // 描述
+ CreateUser string `json:"createUser"` // 创建人
+ UpdateUser string `json:"updateUser"` // 更新人
+ CreateTime string `json:"createTime"` // 创建时间
+ UpdateTime string `json:"updateTime"` // 更新时间
+}
+
+func TestGet(t *testing.T) {
+ res1, err := http.Get[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
+
+ res2, err := http.GetString("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
+}
+
+func TestPost(t *testing.T) {
+ type Role struct {
+ RoleName string `json:"roleName"`
+ }
+ var param = &Role{}
+ res1, err := http.Post[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
+
+ res2, err := http.PostString("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
+
+ res3, err := http.PostForm[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res3)
+
+ res4, err := http.PostFile[Response[any]]("http://localhost:18080/weflow/upload/file", "a.txt", "./testdata/a.txt")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res4)
+
+ res5, err := http.PostFiles[Response[any]]("http://localhost:18080/weflow/upload/file", map[string]string{
+ "a.txt": "./testdata/a.txt",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res5)
+}
+```
+
### config
加载配置:默认加载环境变量、配置文件、命令行参数
- 默认配置文件加载顺序:命令行参数 > 默认配置文件目录(./config/config.yaml)
@@ -361,6 +467,60 @@ func TestUUID(t *testing.T) {
}
```
+### io
+- 文件
+- json
+- yaml
+- toml
+- xml
+- csv
+- excel
+- doc
+- 压缩
+#### io/json
+json序列化和反序列化
+```go
+func TestFormat(t *testing.T) {
+ type Role struct {
+ RoleName string `json:"roleName"`
+ }
+ var param = &Role{
+ RoleName: "admin",
+ }
+ marshal, err := json.Marshal(param)
+ if err != nil {
+ fmt.Errorf("json.Marshal err: %v", err)
+ }
+ fmt.Println(marshal)
+
+ var role = &Role{}
+ err = json.Unmarshal(marshal, role)
+ if err != nil {
+ fmt.Errorf("json.Unmarshal err: %v", err)
+ }
+ fmt.Println(role)
+}
+```
+
+#### io/compress
+字符串压缩
+```go
+func TestCompress(t *testing.T) {
+ var dst []byte
+ var source = []byte("test")
+ encode := compress.Encode(dst, source)
+ fmt.Printf("encode:%s\n", encode)
+ fmt.Printf("dst encode:%s\n", dst)
+ var src []byte
+ decode, err := compress.Decode(encode, src)
+ if err != nil {
+ fmt.Errorf("err:%s\n", err.Error())
+ }
+ fmt.Printf("decode:%s\n", decode)
+ fmt.Printf("src decode:%s\n", src)
+}
+```
+
贡献来源:
https://github.com/spf13/viper
diff --git a/base/response.go b/base/response.go
index f80a85c..890f144 100644
--- a/base/response.go
+++ b/base/response.go
@@ -8,6 +8,14 @@ type Response struct {
Data interface{} `json:"data"` // 数据
}
+// Result
+// @Description: 响应体
+type Result[T any] struct {
+ Code int `json:"code"` // 0:成功,其他:失败
+ Msg string `json:"msg"` // 错误信息
+ Data T `json:"data"` // 数据
+}
+
// NewResponse
// @Description: 创建响应体
// @return *Response
@@ -15,6 +23,13 @@ func NewResponse() *Response {
return &Response{}
}
+// NewResult
+// @Description: 创建响应体
+// @return *Result[T]
+func NewResult[T any]() *Result[T] {
+ return &Result[T]{}
+}
+
// Fail
// @Description: 响应错误
// @receiver: base
diff --git a/example/compress_test.go b/example/compress_test.go
index d7f6489..a3e5d64 100644
--- a/example/compress_test.go
+++ b/example/compress_test.go
@@ -2,7 +2,7 @@ package example
import (
"fmt"
- "github.com/wegoteam/wepkg/compress"
+ "github.com/wegoteam/wepkg/io/compress"
"testing"
)
diff --git a/example/config_test.go b/example/config_test.go
index cc71b80..32dcb5a 100644
--- a/example/config_test.go
+++ b/example/config_test.go
@@ -8,7 +8,7 @@ import (
func TestLoad(t *testing.T) {
config := configUtil.GetConfig()
- config = configUtil.SetConfig("config", "yaml", "", []string{"."})
+ //config = configUtil.SetConfig("config", "yaml", "", []string{"."})
//config := NewConfig("config", "yaml", "", []string{"."})
var mysql = &configUtil.MySQL{}
err := config.Load("mysql", mysql)
diff --git a/example/http_test.go b/example/http_test.go
index 41c66bf..53af6c2 100644
--- a/example/http_test.go
+++ b/example/http_test.go
@@ -2,121 +2,101 @@ package example
import (
"fmt"
- "github.com/go-resty/resty/v2"
- "strconv"
+ "github.com/wegoteam/wepkg/net/http"
"testing"
- "time"
)
-func TestSimpleGet(t *testing.T) {
- // Create a Resty Client
- client := resty.New()
-
+func TestDefaultClientPOST(t *testing.T) {
+ client := http.BuildDefaultClient()
+ var res string
resp, err := client.R().
- EnableTrace().
- Get("https://httpbin.org/get")
+ SetHeader("Content-Type", "application/json").
+ SetBody(`{"roleName":""}`).
+ SetResult(res).
+ Post("http://localhost:18080/weflow/role/list")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", resp)
+ fmt.Println("Response Info:", res)
+}
- // Explore response object
- fmt.Println("Response Info:")
- fmt.Println(" Error :", err)
- fmt.Println(" Status Code:", resp.StatusCode())
- fmt.Println(" Status :", resp.Status())
- fmt.Println(" Proto :", resp.Proto())
- fmt.Println(" Time :", resp.Time())
- fmt.Println(" Received At:", resp.ReceivedAt())
- fmt.Println(" Body :\n", resp)
- fmt.Println()
+type Response[T any] struct {
+ Code int `json:"code"` // 0:成功,其他:失败
+ Msg string `json:"msg"` // 错误信息
+ Data T `json:"data"` // 数据
+}
- // Explore trace info
- fmt.Println("request Trace Info:")
- ti := resp.Request.TraceInfo()
- fmt.Println(" DNSLookup :", ti.DNSLookup)
- fmt.Println(" ConnTime :", ti.ConnTime)
- fmt.Println(" TCPConnTime :", ti.TCPConnTime)
- fmt.Println(" TLSHandshake :", ti.TLSHandshake)
- fmt.Println(" ServerTime :", ti.ServerTime)
- fmt.Println(" ResponseTime :", ti.ResponseTime)
- fmt.Println(" TotalTime :", ti.TotalTime)
- fmt.Println(" IsConnReused :", ti.IsConnReused)
- fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle)
- fmt.Println(" ConnIdleTime :", ti.ConnIdleTime)
- fmt.Println(" RequestAttempt:", ti.RequestAttempt)
- fmt.Println(" RemoteAddr :", ti.RemoteAddr.String())
+type RoleInfoResult struct {
+ ID int64 `json:"id"` // 唯一id
+ RoleID string `json:"roleID"` // 角色id
+ ParentID string `json:"parentID"` // 角色父id
+ RoleName string `json:"roleName"` // 角色名称
+ Status int32 `json:"status"` // 状态【1:未启用;2:已启用;3:锁定;】
+ Remark string `json:"remark"` // 描述
+ CreateUser string `json:"createUser"` // 创建人
+ UpdateUser string `json:"updateUser"` // 更新人
+ CreateTime string `json:"createTime"` // 创建时间
+ UpdateTime string `json:"updateTime"` // 更新时间
}
-func TestEnhancedGET(t *testing.T) {
- // Create a Resty Client
- client := resty.New()
+func TestGet(t *testing.T) {
+ res1, err := http.Get[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
- resp, err := client.R().
- SetQueryParams(map[string]string{
- "page_no": "1",
- "limit": "20",
- "sort": "name",
- "order": "asc",
- "random": strconv.FormatInt(time.Now().Unix(), 10),
- }).
- SetHeader("Accept", "application/json").
- SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F").
- Get("https://httpbin.org/search_result")
- fmt.Println("Response Info:")
- fmt.Println(" Error :", err)
- fmt.Println(" Status Code:", resp.StatusCode())
- fmt.Println(" Status :", resp.Status())
- fmt.Println(" Proto :", resp.Proto())
- fmt.Println(" Time :", resp.Time())
- fmt.Println(" Received At:", resp.ReceivedAt())
- fmt.Println(" Body :\n", resp)
- fmt.Println()
+ res2, err := http.GetString("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
+}
- // Sample of using request.SetQueryString method
- resp, err = client.R().
- SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more").
- SetHeader("Accept", "application/json").
- SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F").
- Get("https://httpbin.org/show_product")
- fmt.Println("Response Info:")
- fmt.Println(" Error :", err)
- fmt.Println(" Status Code:", resp.StatusCode())
- fmt.Println(" Status :", resp.Status())
- fmt.Println(" Proto :", resp.Proto())
- fmt.Println(" Time :", resp.Time())
- fmt.Println(" Received At:", resp.ReceivedAt())
- fmt.Println(" Body :\n", resp)
- fmt.Println()
+func TestPost(t *testing.T) {
+ type Role struct {
+ RoleName string `json:"roleName"`
+ }
+ var param = &Role{}
+ res1, err := http.Post[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
- var result string
- // If necessary, you can force response content type to tell Resty to parse a JSON response into your struct
- resp, err = client.R().
- SetResult(result).
- ForceContentType("application/json").
- Get("https://httpbin.org/v2/alpine/manifests/latest")
+ res2, err := http.PostString("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
- fmt.Println("Response Info:")
- fmt.Println(" Error :", err)
- fmt.Println(" Status Code:", resp.StatusCode())
- fmt.Println(" Status :", resp.Status())
- fmt.Println(" Proto :", resp.Proto())
- fmt.Println(" Time :", resp.Time())
- fmt.Println(" Received At:", resp.ReceivedAt())
- fmt.Println(" Body :\n", resp)
- fmt.Println()
-}
+ res3, err := http.PostForm[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res3)
-func TestVariousPOST(t *testing.T) {
- // Create a Resty Client
- client := resty.New()
+ res4, err := http.PostFile[Response[any]]("http://localhost:18080/weflow/upload/file", "a.txt", "./testdata/a.txt")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res4)
- var res string
- // POST JSON string
- // No need to set content type, if you have client level setting
- resp, err := client.R().
- SetHeader("Content-Type", "application/json").
- SetBody(`{"roleName":""}`).
- SetResult(res). // or SetResult(AuthSuccess{}).
- Post("http://localhost:18080/weflow/role/list")
+ res5, err := http.PostFiles[Response[any]]("http://localhost:18080/weflow/upload/file", map[string]string{
+ "a.txt": "./testdata/a.txt",
+ })
if err != nil {
fmt.Println("err:", err)
}
- fmt.Println("Response Info:", resp)
+ fmt.Println("Response Info:", res5)
}
diff --git a/example/json_test.go b/example/json_test.go
new file mode 100644
index 0000000..64afa09
--- /dev/null
+++ b/example/json_test.go
@@ -0,0 +1,28 @@
+package example
+
+import (
+ "fmt"
+ "github.com/wegoteam/wepkg/io/json"
+ "testing"
+)
+
+func TestFormat(t *testing.T) {
+ type Role struct {
+ RoleName string `json:"roleName"`
+ }
+ var param = &Role{
+ RoleName: "admin",
+ }
+ marshal, err := json.Marshal(param)
+ if err != nil {
+ fmt.Errorf("json.Marshal err: %v", err)
+ }
+ fmt.Println(marshal)
+
+ var role = &Role{}
+ err = json.Unmarshal(marshal, role)
+ if err != nil {
+ fmt.Errorf("json.Unmarshal err: %v", err)
+ }
+ fmt.Println(role)
+}
diff --git a/example/testdata/a.txt b/example/testdata/a.txt
new file mode 100644
index 0000000..95d09f2
--- /dev/null
+++ b/example/testdata/a.txt
@@ -0,0 +1 @@
+hello world
\ No newline at end of file
diff --git a/go.mod b/go.mod
index ca5b32a..92fcf4a 100644
--- a/go.mod
+++ b/go.mod
@@ -24,7 +24,9 @@ require (
)
require (
+ github.com/bytedance/sonic v1.9.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
+ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emmansun/gmsm v0.19.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
@@ -34,6 +36,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
+ github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
@@ -43,10 +46,12 @@ require (
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
+ golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
diff --git a/go.sum b/go.sum
index 962be92..8471f8d 100644
--- a/go.sum
+++ b/go.sum
@@ -42,9 +42,15 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
+github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
+github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM=
+github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
+github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
+github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -160,6 +166,9 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
+github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
+github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -219,6 +228,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
+github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
+github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
@@ -245,6 +256,8 @@ go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
+golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
+golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -593,5 +606,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
+rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/compress/compress.go b/io/compress/compress.go
similarity index 100%
rename from compress/compress.go
rename to io/compress/compress.go
diff --git a/file/excel/excel.go b/io/excel/excel.go
similarity index 100%
rename from file/excel/excel.go
rename to io/excel/excel.go
diff --git a/file/file.go b/io/files/file.go
similarity index 73%
rename from file/file.go
rename to io/files/file.go
index 2a1d86b..07d880e 100644
--- a/file/file.go
+++ b/io/files/file.go
@@ -1,3 +1,3 @@
-package file
+package files
//github.com/gabriel-vasile/mimetype
diff --git a/io/json/format.go b/io/json/format.go
new file mode 100644
index 0000000..ee1235d
--- /dev/null
+++ b/io/json/format.go
@@ -0,0 +1,23 @@
+package json
+
+// 引用:https://github.com/bytedance/sonic
+
+import jsonUtil "github.com/bytedance/sonic"
+
+// Marshal
+// @Description: 序列化
+// @param: val 传入对象
+// @return string 序列化后的字符串
+// @return error
+func Marshal(val interface{}) (string, error) {
+ return jsonUtil.MarshalString(val)
+}
+
+// Unmarshal
+// @Description: 反序列化
+// @param: buf 传入字符串
+// @param: val 传入指针
+// @return error
+func Unmarshal(buf string, val interface{}) error {
+ return jsonUtil.UnmarshalString(buf, val)
+}
diff --git a/io/xml/xml.go b/io/xml/xml.go
new file mode 100644
index 0000000..9b26c59
--- /dev/null
+++ b/io/xml/xml.go
@@ -0,0 +1 @@
+package xml
diff --git a/net/http/http.go b/net/http/http.go
index d662283..45bd713 100644
--- a/net/http/http.go
+++ b/net/http/http.go
@@ -2,6 +2,7 @@ package http
import (
httpUtil "github.com/go-resty/resty/v2"
+ "time"
)
const (
@@ -10,6 +11,13 @@ const (
ApplicationJSON = "application/json"
)
+// BuildDefaultClient
+// @Description: 获取http客户端
+// @return *httpUtil.Client
+func BuildDefaultClient() *httpUtil.Client {
+ return httpUtil.New().SetTimeout(30 * time.Second)
+}
+
// BuildClient
// @Description: 获取http客户端
// @return *httpUtil.Client
@@ -21,16 +29,16 @@ func BuildClient() *httpUtil.Client {
// @Description: 获取http请求
// @return *httpUtil.Request
func BuildRequest() *httpUtil.Request {
- return BuildClient().R()
+ return BuildDefaultClient().R()
}
// Get
// @Description: Get请求
-// @param: url
-// @param: params
-// @return T
+// @param: url 请求地址
+// @param: params 请求参数
+// @return T 返回对象
// @return error
-func Get[T comparable](url string, params map[string]string) (T, error) {
+func Get[T any](url string, params map[string]string) (T, error) {
var result T
_, err := BuildRequest().
SetQueryParams(params).
@@ -41,13 +49,28 @@ func Get[T comparable](url string, params map[string]string) (T, error) {
return result, err
}
-// GetQueryString
+// GetString
+// @Description: Get请求
+// @param: url 请求地址
+// @param: params 请求参数
+// @return string 返回字符串
+// @return error
+func GetString(url string, params map[string]string) (string, error) {
+ resp, err := BuildRequest().
+ SetQueryParams(params).
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetHeader(AcceptHead, ApplicationJSON).
+ Get(url)
+ return resp.String(), err
+}
+
+// GetQuery
// @Description: Get请求
// @param: url
-// @param: params productId=232&template=2这样形式
+// @param: params:productId=232&template=2 这样形式
// @return T
// @return error
-func GetQueryString[T comparable](url string, params string) (T, error) {
+func GetQuery[T any](url string, params string) (T, error) {
var result T
_, err := BuildRequest().
SetQueryString(params).
@@ -58,13 +81,28 @@ func GetQueryString[T comparable](url string, params string) (T, error) {
return result, err
}
+// GetQueryString
+// @Description: Get请求
+// @param: url 请求地址
+// @param: params 请求参数
+// @return string 返回字符串
+// @return error
+func GetQueryString(url string, params string) (string, error) {
+ resp, err := BuildRequest().
+ SetQueryString(params).
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetHeader(AcceptHead, ApplicationJSON).
+ Get(url)
+ return resp.String(), err
+}
+
// Post
// @Description: Post请求
// @param: url
// @param: body
// @return T
// @return error
-func Post[T comparable](url string, body interface{}) (T, error) {
+func Post[T any](url string, body interface{}) (T, error) {
var result T
_, err := BuildRequest().
SetBody(body).
@@ -74,13 +112,27 @@ func Post[T comparable](url string, body interface{}) (T, error) {
return result, err
}
+// PostString
+// @Description: Post请求
+// @param: url 请求地址
+// @param: body 请求参数
+// @return string 返回字符串
+// @return error
+func PostString(url string, body interface{}) (string, error) {
+ resp, err := BuildRequest().
+ SetBody(body).
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ Post(url)
+ return resp.String(), err
+}
+
// PostForm
// @Description: PostForm请求
// @param: url
// @param: formParam
// @return T
// @return error
-func PostForm[T comparable](url string, formParam map[string]string) (T, error) {
+func PostForm[T any](url string, formParam map[string]string) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -90,14 +142,28 @@ func PostForm[T comparable](url string, formParam map[string]string) (T, error)
return result, err
}
+// PostFormString
+// @Description: PostForm请求
+// @param: url 请求地址
+// @param: formParam 请求参数
+// @return string 返回字符串
+// @return error
+func PostFormString(url string, formParam map[string]string) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetFormData(formParam).
+ Post(url)
+ return resp.String(), err
+}
+
// PostFile
// @Description: PostFile请求
-// @param: url
-// @param: fileName
-// @param: filePath
-// @return T
+// @param: url 请求地址
+// @param: fileName 文件名
+// @param: filePath 文件路径
+// @return T 返回对象
// @return error
-func PostFile[T comparable](url, fileName, filePath string) (T, error) {
+func PostFile[T any](url, fileName, filePath string) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -107,13 +173,28 @@ func PostFile[T comparable](url, fileName, filePath string) (T, error) {
return result, err
}
+// PostFileString
+// @Description: PostFile请求
+// @param: url 请求地址
+// @param: fileName 文件名
+// @param: filePath 文件路径
+// @return string 返回字符串
+// @return error
+func PostFileString(url, fileName, filePath string) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetFile(fileName, filePath).
+ Post(url)
+ return resp.String(), err
+}
+
// PostFiles
// @Description: PostFiles请求
-// @param: url
-// @param: files
-// @return T
+// @param: url 请求地址
+// @param: files 文件
+// @return T 返回对象
// @return error
-func PostFiles[T comparable](url string, files map[string]string) (T, error) {
+func PostFiles[T any](url string, files map[string]string) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -123,6 +204,20 @@ func PostFiles[T comparable](url string, files map[string]string) (T, error) {
return result, err
}
+// PostFilesString
+// @Description: PostFiles请求
+// @param: url 请求地址
+// @param: files 文件
+// @return string 返回字符串
+// @return error
+func PostFilesString(url string, files map[string]string) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetFiles(files).
+ Post(url)
+ return resp.String(), err
+}
+
// PostFormFile
// @Description: PostFormFile请求
// @param: url
@@ -131,7 +226,7 @@ func PostFiles[T comparable](url string, files map[string]string) (T, error) {
// @param: formParam
// @return T
// @return error
-func PostFormFile[T comparable](url, fileName, filePath string, formParam map[string]string) (T, error) {
+func PostFormFile[T any](url, fileName, filePath string, formParam map[string]string) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -142,6 +237,23 @@ func PostFormFile[T comparable](url, fileName, filePath string, formParam map[st
return result, err
}
+// PostFormFileString
+// @Description: PostFormFile请求
+// @param: url 请求地址
+// @param: fileName 文件名
+// @param: filePath 文件路径
+// @param: formParam 请求参数
+// @return string 返回字符串
+// @return error
+func PostFormFileString(url, fileName, filePath string, formParam map[string]string) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetFormData(formParam).
+ SetFile(fileName, filePath).
+ Post(url)
+ return resp.String(), err
+}
+
// PostFormFiles
// @Description: PostFormFiles请求
// @param: url
@@ -149,7 +261,7 @@ func PostFormFile[T comparable](url, fileName, filePath string, formParam map[st
// @param: files
// @return T
// @return error
-func PostFormFiles[T comparable](url string, formParam, files map[string]string) (T, error) {
+func PostFormFiles[T any](url string, formParam, files map[string]string) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -160,13 +272,29 @@ func PostFormFiles[T comparable](url string, formParam, files map[string]string)
return result, err
}
+// PostFormFilesString
+// @Description: PostFormFiles请求
+// @param: url 请求地址
+// @param: formParam 请求参数
+// @param: files 文件
+// @return string 返回字符串
+// @return error
+func PostFormFilesString(url string, formParam, files map[string]string) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetFormData(formParam).
+ SetFiles(files).
+ Post(url)
+ return resp.String(), err
+}
+
// Put
// @Description: Put请求
// @param: url
// @param: body
// @return T
// @return error
-func Put[T comparable](url string, body interface{}) (T, error) {
+func Put[T any](url string, body interface{}) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -176,13 +304,27 @@ func Put[T comparable](url string, body interface{}) (T, error) {
return result, err
}
+// PutString
+// @Description: Put请求
+// @param: url 请求地址
+// @param: body 请求参数
+// @return string 返回字符串
+// @return error
+func PutString(url string, body interface{}) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetBody(body).
+ Put(url)
+ return resp.String(), err
+}
+
// Patch
// @Description: Patch请求
// @param: url
// @param: body
// @return T
// @return error
-func Patch[T comparable](url string, body interface{}) (T, error) {
+func Patch[T any](url string, body interface{}) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -192,13 +334,27 @@ func Patch[T comparable](url string, body interface{}) (T, error) {
return result, err
}
+// PatchString
+// @Description: Patch请求
+// @param: url 请求地址
+// @param: body 请求参数
+// @return string 返回字符串
+// @return error
+func PatchString(url string, body interface{}) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetBody(body).
+ Patch(url)
+ return resp.String(), err
+}
+
// Delete
// @Description: Delete请求
// @param: url
// @param: body
// @return T
// @return error
-func Delete[T comparable](url string, body interface{}) (T, error) {
+func Delete[T any](url string, body interface{}) (T, error) {
var result T
_, err := BuildRequest().
SetHeader(ContentTypeHead, ApplicationJSON).
@@ -207,3 +363,17 @@ func Delete[T comparable](url string, body interface{}) (T, error) {
Delete(url)
return result, err
}
+
+// DeleteString
+// @Description: Delete请求
+// @param: url 请求地址
+// @param: body 请求参数
+// @return string 返回字符串
+// @return error
+func DeleteString(url string, body interface{}) (string, error) {
+ resp, err := BuildRequest().
+ SetHeader(ContentTypeHead, ApplicationJSON).
+ SetBody(body).
+ Delete(url)
+ return resp.String(), err
+}
From b75f671161d104ed27165ef14a95f0b2f3979eeb Mon Sep 17 00:00:00 2001
From: xuchang <574616156@qq.com>
Date: Fri, 28 Jul 2023 18:35:04 +0800
Subject: [PATCH 2/4] =?UTF-8?q?v1.0.5=20http=E3=80=81config=E3=80=81json?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 03b8ea1..70f8a75 100644
--- a/README.md
+++ b/README.md
@@ -403,7 +403,7 @@ snowflake:
method: 1
#基础时间(ms单位),不能超过当前系统时间
baseTime: 1582136402000
- #机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1
+ #机器码,必须由外部设定,最大值 2^bitLength-1
workerId: 1
#机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
bitLength: 6
From c656b252edfee7a18c9254ecb7cb1b663deb9f74 Mon Sep 17 00:00:00 2001
From: xuchang <574616156@qq.com>
Date: Wed, 2 Aug 2023 19:11:34 +0800
Subject: [PATCH 3/4] =?UTF-8?q?v1.0.5=20http=E3=80=81config=E3=80=81json?=
=?UTF-8?q?=E3=80=81log=E3=80=81xml?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 321 ++++++++++++-------
base/page.go | 2 +-
base/response.go | 61 ++++
config/load.go | 6 +-
datetime/datetime.go | 25 +-
example/config/config.yaml | 17 +
example/log/log.txt | 149 +++++++++
example/log/log2.txt | 13 +
example/logs_test.go | 57 ++++
example/xml_test.go | 172 ++++++++++
go.mod | 24 +-
go.sum | 69 ++--
io/xml/fromat.go | 24 ++
{cron => job/cron}/cron.go | 0
job/xxljob/xxljob.go | 3 +
lock/{distributedlock => rlock}/redislock.go | 31 +-
log/log_test.go | 7 -
log/logrus-logger.go | 62 ----
log/logrus/logrus.go | 148 +++++++++
log/logrus/option.go | 47 +++
log/option.go | 157 +++++++++
log/slog-logger.go | 62 ----
log/wlog/consts.go | 7 +
log/wlog/default.go | 228 +++++++++++++
log/wlog/log.go | 88 +++++
log/wlog/logger.go | 64 ++++
log/wlog/system.go | 139 ++++++++
log/zap-logger.go | 59 ----
log/zerolog-logger.go | 58 ----
29 files changed, 1643 insertions(+), 457 deletions(-)
create mode 100644 example/log/log.txt
create mode 100644 example/log/log2.txt
create mode 100644 example/logs_test.go
create mode 100644 example/xml_test.go
create mode 100644 io/xml/fromat.go
rename {cron => job/cron}/cron.go (100%)
create mode 100644 job/xxljob/xxljob.go
rename lock/{distributedlock => rlock}/redislock.go (71%)
delete mode 100644 log/log_test.go
delete mode 100644 log/logrus-logger.go
create mode 100644 log/logrus/logrus.go
create mode 100644 log/logrus/option.go
create mode 100644 log/option.go
delete mode 100644 log/slog-logger.go
create mode 100644 log/wlog/consts.go
create mode 100644 log/wlog/default.go
create mode 100644 log/wlog/log.go
create mode 100644 log/wlog/logger.go
create mode 100644 log/wlog/system.go
delete mode 100644 log/zap-logger.go
delete mode 100644 log/zerolog-logger.go
diff --git a/README.md b/README.md
index 70f8a75..11c8b9a 100644
--- a/README.md
+++ b/README.md
@@ -11,11 +11,14 @@
- 条件表达式
- 协程池
- 切片
+- 日志
+- 定时任务
...
## 更新记录
+- v1.0.5:json、xml、log
- v1.0.4:datatime、http、config、crypto、uuid/ulid
- v1.0.3:加载配置
- v1.0.1:雪花算法
@@ -35,114 +38,7 @@ go get -u github.com/wegoteam/wepkg@latest
- 响应结构体
- 分页
-### net
-- http client的封装(get post put...)
-- rpc
-- websocket
-- tcp
-- udp
-- grpc
-- mqtt
-- nats
-#### net/http
-封装http请求的客户端
-
-```go
-func TestDefaultClientPOST(t *testing.T) {
- client := http.BuildDefaultClient()
- var res string
- resp, err := client.R().
- SetHeader("Content-Type", "application/json").
- SetBody(`{"roleName":""}`).
- SetResult(res).
- Post("http://localhost:18080/weflow/role/list")
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", resp)
- fmt.Println("Response Info:", res)
-}
-
-type Response[T any] struct {
- Code int `json:"code"` // 0:成功,其他:失败
- Msg string `json:"msg"` // 错误信息
- Data T `json:"data"` // 数据
-}
-
-type RoleInfoResult struct {
- ID int64 `json:"id"` // 唯一id
- RoleID string `json:"roleID"` // 角色id
- ParentID string `json:"parentID"` // 角色父id
- RoleName string `json:"roleName"` // 角色名称
- Status int32 `json:"status"` // 状态【1:未启用;2:已启用;3:锁定;】
- Remark string `json:"remark"` // 描述
- CreateUser string `json:"createUser"` // 创建人
- UpdateUser string `json:"updateUser"` // 更新人
- CreateTime string `json:"createTime"` // 创建时间
- UpdateTime string `json:"updateTime"` // 更新时间
-}
-
-func TestGet(t *testing.T) {
- res1, err := http.Get[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
- map[string]string{
- "roleName": "",
- })
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res1)
-
- res2, err := http.GetString("http://localhost:18080/weflow/role/list",
- map[string]string{
- "roleName": "",
- })
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res2)
-}
-
-func TestPost(t *testing.T) {
- type Role struct {
- RoleName string `json:"roleName"`
- }
- var param = &Role{}
- res1, err := http.Post[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list", param)
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res1)
-
- res2, err := http.PostString("http://localhost:18080/weflow/role/list", param)
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res2)
-
- res3, err := http.PostForm[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
- map[string]string{
- "roleName": "",
- })
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res3)
- res4, err := http.PostFile[Response[any]]("http://localhost:18080/weflow/upload/file", "a.txt", "./testdata/a.txt")
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res4)
-
- res5, err := http.PostFiles[Response[any]]("http://localhost:18080/weflow/upload/file", map[string]string{
- "a.txt": "./testdata/a.txt",
- })
- if err != nil {
- fmt.Println("err:", err)
- }
- fmt.Println("Response Info:", res5)
-}
-```
### config
加载配置:默认加载环境变量、配置文件、命令行参数
@@ -279,7 +175,10 @@ func TestTime(t *testing.T) {
```
### bean
-属性复制、结构体转map、map转结构体
+-[x] 属性复制
+-[x] 结构体转map
+-[x] map转结构体
+-[x] 结构体字段、tag、值获取
```go
type A struct {
Age int `json:"age"`
@@ -467,16 +366,204 @@ func TestUUID(t *testing.T) {
}
```
+### log
+日志记录:支持日志文件切割,日志级别,日志格式化,日志文件压缩,日志文件清理
+
+配置文件设置方式:配置文件、手动设置
+- 日志配置配置读取./config/config.yaml文件的配置
+```yaml
+#日志配置
+logger:
+ #日志输出格式,可选项:json、text
+ format: text
+ #日志级别,可选项:trace、debug、info、warn、error、panic、fatal
+ level: info
+ #日志输出位置,可选项:console、file;多个用逗号分隔
+ output: console,file
+ #日志文件名
+ fileName: "./log/wegopkg.log"
+ #日志文件最大大小,单位:MB
+ maxSize: 10
+ #日志文件最大保存时间,单位:天
+ maxAge: 3
+ #日志文件最大备份数量
+ maxBackups: 50
+```
+- 设置SetLoggerConfig方法的参数配置日志
+```go
+func TestLogConfig(t *testing.T) {
+ log.SetLoggerConfig(log.LoggerConfig{
+ Level: "trace",
+ Format: "text",
+ Output: "console",
+ })
+ config := log.GetLoggerConfig()
+ fmt.Printf("config=%v\n", config)
+ log.Trace("Something very low level.")
+ log.Debug("Useful debugging information.")
+ log.Info("Something noteworthy happened!")
+}
+```
+
+使用方法
+```go
+func TestLog(t *testing.T) {
+ log.Trace("Something very low level.")
+ log.Tracef("Something very low level. %s", "test")
+ log.Traceln("Something very low level.")
+
+ log.Debug("Useful debugging information.")
+ log.Debugf("Useful debugging information. %s", "test")
+ log.Debugln("Useful debugging information.")
+
+ log.Info("Something noteworthy happened!")
+ log.Infof("Something noteworthy happened! %s", "test")
+ log.Infoln("Something noteworthy happened!")
+
+ log.Notice("Something unusual happened.")
+ log.Noticef("Something unusual happened. %s", "test")
+ log.Noticef("Something unusual happened.")
+
+ log.Warn("You should probably take a look at this.")
+ log.Warnf("You should probably take a look at this. %s", "test")
+ log.Warnln("You should probably take a look at this.")
+
+ log.Error("Something failed but I'm not quitting.")
+ log.Errorf("Something failed but I'm not quitting. %s", "test")
+ log.Errorln("Something failed but I'm not quitting.")
+
+ // Calls os.Exit(1) after logging
+ log.Fatal("Bye.")
+ log.Fatalf("Bye. %s", "test")
+ log.Fatalln("Bye.")
+
+ // Calls panic() after logging
+ log.Panic("I'm bailing.")
+ log.Panicf("I'm bailing. %s", "test")
+ log.Panicln("I'm bailing.")
+
+}
+```
+
+
+### net
+-[x] http client的封装(get post put...)
+-[ ] rpc
+-[ ] websocket
+-[ ] tcp
+-[ ] udp
+-[ ] grpc
+-[ ] mqtt
+-[ ] nats
+#### net/http
+封装http请求的客户端
+
+```go
+func TestDefaultClientPOST(t *testing.T) {
+ client := http.BuildDefaultClient()
+ var res string
+ resp, err := client.R().
+ SetHeader("Content-Type", "application/json").
+ SetBody(`{"roleName":""}`).
+ SetResult(res).
+ Post("http://localhost:18080/weflow/role/list")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", resp)
+ fmt.Println("Response Info:", res)
+}
+
+type Response[T any] struct {
+ Code int `json:"code"` // 0:成功,其他:失败
+ Msg string `json:"msg"` // 错误信息
+ Data T `json:"data"` // 数据
+}
+
+type RoleInfoResult struct {
+ ID int64 `json:"id"` // 唯一id
+ RoleID string `json:"roleID"` // 角色id
+ ParentID string `json:"parentID"` // 角色父id
+ RoleName string `json:"roleName"` // 角色名称
+ Status int32 `json:"status"` // 状态【1:未启用;2:已启用;3:锁定;】
+ Remark string `json:"remark"` // 描述
+ CreateUser string `json:"createUser"` // 创建人
+ UpdateUser string `json:"updateUser"` // 更新人
+ CreateTime string `json:"createTime"` // 创建时间
+ UpdateTime string `json:"updateTime"` // 更新时间
+}
+
+func TestGet(t *testing.T) {
+ res1, err := http.Get[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
+
+ res2, err := http.GetString("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
+}
+
+func TestPost(t *testing.T) {
+ type Role struct {
+ RoleName string `json:"roleName"`
+ }
+ var param = &Role{}
+ res1, err := http.Post[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res1)
+
+ res2, err := http.PostString("http://localhost:18080/weflow/role/list", param)
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res2)
+
+ res3, err := http.PostForm[Response[[]RoleInfoResult]]("http://localhost:18080/weflow/role/list",
+ map[string]string{
+ "roleName": "",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res3)
+
+ res4, err := http.PostFile[Response[any]]("http://localhost:18080/weflow/upload/file", "a.txt", "./testdata/a.txt")
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res4)
+
+ res5, err := http.PostFiles[Response[any]]("http://localhost:18080/weflow/upload/file", map[string]string{
+ "a.txt": "./testdata/a.txt",
+ })
+ if err != nil {
+ fmt.Println("err:", err)
+ }
+ fmt.Println("Response Info:", res5)
+}
+```
+
### io
-- 文件
-- json
-- yaml
-- toml
-- xml
-- csv
-- excel
-- doc
-- 压缩
+-[ ] 文件
+-[x] json
+-[x] xml
+-[ ] csv
+-[ ] excel
+-[ ] doc
+-[x] 压缩字符串
+-[ ] 压缩文件
#### io/json
json序列化和反序列化
```go
diff --git a/base/page.go b/base/page.go
index b324beb..04e5ca7 100644
--- a/base/page.go
+++ b/base/page.go
@@ -6,7 +6,7 @@ import (
// Page
// @Description: 分页实体
-type Page[T comparable] struct {
+type Page[T any] struct {
Total int64 `json:"total"`
PageNum int `json:"pageNum"`
PageSize int `json:"pageSize"`
diff --git a/base/response.go b/base/response.go
index 890f144..8772735 100644
--- a/base/response.go
+++ b/base/response.go
@@ -41,6 +41,18 @@ func (response *Response) Fail(code int, err string) *Response {
return response
}
+// Fail
+// @Description: 响应错误
+// @receiver: response
+// @param: code
+// @param: err
+// @return *Result[T]
+func (response *Result[T]) Fail(code int, err string) *Result[T] {
+ response.Code = code
+ response.Msg = err
+ return response
+}
+
// Fail
// @Description: 响应错误
// @param: code
@@ -59,6 +71,20 @@ func Fail(code int, err string) *Response {
// @param: code
// @param: data
// @param: err
+func (response *Result[T]) FailData(code int, data interface{}, err string) *Result[T] {
+ response.Code = code
+ response.Msg = err
+ response.Data = data
+ return response
+}
+
+// FailData
+// @Description: 响应错误
+// @receiver: response
+// @param: code
+// @param: data
+// @param: err
+// @return *Response
func (response *Response) FailData(code int, data interface{}, err string) *Response {
response.Code = code
response.Msg = err
@@ -91,6 +117,16 @@ func (response *Response) Success() *Response {
return response
}
+// Success
+// @Description: 响应成功
+// @receiver: response
+// @return *Result[T]
+func (response *Result[T]) Success() *Result[T] {
+ response.Code = 0
+ response.Msg = "success"
+ return response
+}
+
// Success
// @Description: 响应成功
// @return *Response
@@ -113,6 +149,18 @@ func (response *Response) OK(data interface{}) *Response {
return response
}
+// OK
+// @Description: 响应成功
+// @receiver: response
+// @param: data
+// @return *Result[T]
+func (response *Result[T]) OK(data interface{}) *Result[T] {
+ response.Code = 0
+ response.Data = data
+ response.Msg = "success"
+ return response
+}
+
// OK
// @Description: 响应成功
// @param: data
@@ -137,6 +185,19 @@ func (response *Response) OkMsg(data interface{}, err string) *Response {
return response
}
+// OkMsg
+// @Description: 响应成功
+// @receiver: response
+// @param: data
+// @param: err
+// @return *Result[T]
+func (response *Result[T]) OkMsg(data interface{}, err string) *Result[T] {
+ response.Code = 0
+ response.Data = data
+ response.Msg = err
+ return response
+}
+
// OkMsg
// @Description: 响应成功
// @param: data
diff --git a/config/load.go b/config/load.go
index 90c8b7c..40b272d 100644
--- a/config/load.go
+++ b/config/load.go
@@ -109,7 +109,7 @@ func NewConfig(configName, configType, profiles string, confPaths []string) *Con
func initConfig() {
defer func() {
if err := recover(); err != nil {
- fmt.Println("initConfig panic", err)
+ fmt.Errorf("initConfig panic %v \n", err)
}
}()
var profiles, configPath string
@@ -167,8 +167,8 @@ func parseFilePath(files string) (paths, fileName, fileType string) {
// Load
// @Description: 加载配置文件
-// @param: prefix
-// @param: data
+// @param: prefix 配置文件前缀
+// @param: data 配置文件数据指针地址
// @return error
func (config *Config) Load(prefix string, data interface{}) error {
c := config.Config
diff --git a/datetime/datetime.go b/datetime/datetime.go
index 73fadaf..f30183f 100644
--- a/datetime/datetime.go
+++ b/datetime/datetime.go
@@ -18,16 +18,19 @@ import (
)
const (
- DefaultDateTimePatternMilli = "Y-m-d H:i:s"
- DefaultDateTimePatternMicro = "Y-m-d H:i:s.u"
- DefaultDateTimePatternNano = "Y-m-d H:i:s.U"
- DateTimeLayout = "2006-01-02 15:04:05"
- DateTimeMilliLayout = "2006-01-02 15:04:05.999"
- DateTimeMicroLayout = "2006-01-02 15:04:05.999999"
- DateTimeNanoLayout = "2006-01-02 15:04:05.999999999"
- PinyinDateTimeLayout = "2006年01月02日 15时04分05秒"
- Pinyin2DateTimeLayout = "2006年01月02日15时04分05秒"
- UnderlineDateTimeLayout = "2006/01/02 15:04:05"
+ DefaultDateTimePatternMilli = "Y-m-d H:i:s"
+ DefaultDateTimePatternMicro = "Y-m-d H:i:s.u"
+ DefaultDateTimePatternNano = "Y-m-d H:i:s.U"
+ DateTimeLayout = "2006-01-02 15:04:05"
+ DateTimeMilliLayout = "2006-01-02 15:04:05.000"
+ DateTimeMicroLayout = "2006-01-02 15:04:05.000000"
+ DateTimeNanoLayout = "2006-01-02 15:04:05.000000000"
+ PinyinDateTimeLayout = "2006年01月02日 15时04分05秒"
+ Pinyin2DateTimeLayout = "2006年01月02日15时04分05秒"
+ UnderlineDateTimeLayout = "2006/01/02 15:04:05"
+ UnderlineDateTimeMilliLayout = "2006/01/02 15:04:05.000"
+ UnderlineDateTimeMicroLayout = "2006/01/02 15:04:05.000000"
+ UnderlineDateTimeNanoLayout = "2006/01/02 15:04:05.000000000"
)
// From
@@ -79,7 +82,7 @@ func Timestamp() int64 {
// @Description: 获取当前毫秒级时间戳
// @return int64
func TimestampMilli() int64 {
- //return time.Now().UnixNano()
+ //return time.Now().UnixMilli()
return timeUtil.Now().TimestampMilli()
}
diff --git a/example/config/config.yaml b/example/config/config.yaml
index ef7e453..4964bc7 100755
--- a/example/config/config.yaml
+++ b/example/config/config.yaml
@@ -43,3 +43,20 @@ snowflake:
bitLength: 6
#序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
seqBitLength: 6
+
+#日志配置
+logger:
+ #日志输出格式,可选项:json、text
+ format: text
+ #日志级别,可选项:trace、debug、info、warn、error、panic、fatal
+ level: info
+ #日志输出位置,可选项:console、file;多个用逗号分隔
+ output: console,file
+ #日志文件名
+ fileName: "./log/wegopkg.log"
+ #日志文件最大大小,单位:MB
+ maxSize: 10
+ #日志文件最大保存时间,单位:天
+ maxAge: 3
+ #日志文件最大备份数量
+ maxBackups: 50
\ No newline at end of file
diff --git a/example/log/log.txt b/example/log/log.txt
new file mode 100644
index 0000000..e0e906c
--- /dev/null
+++ b/example/log/log.txt
@@ -0,0 +1,149 @@
+time="2023-08-01T20:22:33+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-01T20:22:33+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-01T20:22:33+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-01T20:22:33+08:00" level=fatal msg=Bye.
+[36mINFO[0m[0000] Something noteworthy happened!
+[33mWARN[0m[0000] You should probably take a look at this.
+[31mERRO[0m[0000] Something failed but I'm not quitting.
+[31mFATA[0m[0000] Bye.
+time="2023-08-01T20:24:20+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-01T20:24:20+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-01T20:24:20+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-01T20:24:20+08:00" level=fatal msg=Bye.
+time="2023-08-02T08:57:44+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T08:57:44+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T08:57:44+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T08:57:44+08:00" level=fatal msg=Bye.
+time="2023-08-02T08:58:08+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T08:58:08+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T08:58:08+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T08:58:08+08:00" level=fatal msg=Bye.
+time="2023-08-02T08:58:50+08:00" level=trace msg="Something very low level."
+time="2023-08-02T08:58:50+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T08:58:50+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T08:58:50+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T08:58:50+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T08:58:50+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:28:48+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:28:48+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:28:48+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:28:48+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:28:48+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:28:48+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:29:03+08:00" level=trace msg="Something very low level. test"
+time="2023-08-02T09:29:03+08:00" level=debug msg="Useful debugging information. test"
+time="2023-08-02T09:29:03+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:29:03+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:29:03+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:29:03+08:00" level=fatal msg="Bye. test"
+time="2023-08-02T09:29:57+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:29:57+08:00" level=trace msg="Something very low level. test"
+time="2023-08-02T09:29:57+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:29:57+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:29:57+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:29:57+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:29:57+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level. test"
+time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information. test"
+time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:32:49+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level. test"
+time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level."
+time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information. test"
+time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information."
+time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:33:53+08:00" level=panic msg="I'm bailing."
+[36mINFO[0m[0000] Something noteworthy happened!
+[36mINFO[0m[0000] Something noteworthy happened! test
+[36mINFO[0m[0000] Something noteworthy happened!
+[33mWARN[0m[0000] You should probably take a look at this.
+[33mWARN[0m[0000] You should probably take a look at this. test
+[33mWARN[0m[0000] You should probably take a look at this.
+[31mERRO[0m[0000] Something failed but I'm not quitting.
+[31mERRO[0m[0000] Something failed but I'm not quitting. test
+[31mERRO[0m[0000] Something failed but I'm not quitting.
+[31mFATA[0m[0000] Bye.
+time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:37:38+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened."
+time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened. test"
+time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened."
+time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:45:58+08:00" level=fatal msg=Bye.
+time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened! test"
+time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened!"
+time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened."
+time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened. test"
+time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened."
+time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this. test"
+time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this."
+time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting. test"
+time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting."
+time="2023-08-02T09:55:26+08:00" level=fatal msg=Bye.
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:84"
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:143"
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:204"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:91"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:98"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:159"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:218"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:105"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:167"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:225"
+time="2023-08-02T10:57:31+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:119"
+time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:21"
+time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:80"
+time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:141"
+time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:28"
+time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:88"
+time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:88"
+time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:35"
+time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:96"
+time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:155"
+time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:42"
+time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:104"
+time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:162"
+time="2023-08-02T17:42:21+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:56"
diff --git a/example/log/log2.txt b/example/log/log2.txt
new file mode 100644
index 0000000..5c39710
--- /dev/null
+++ b/example/log/log2.txt
@@ -0,0 +1,13 @@
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:84"
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:143"
+time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:204"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:91"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
+time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:98"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:159"
+time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:218"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:105"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:167"
+time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:225"
+time="2023-08-02T10:57:31+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:119"
diff --git a/example/logs_test.go b/example/logs_test.go
new file mode 100644
index 0000000..e84df2f
--- /dev/null
+++ b/example/logs_test.go
@@ -0,0 +1,57 @@
+package example
+
+import (
+ "fmt"
+ "github.com/wegoteam/wepkg/log"
+ "testing"
+)
+
+func TestLogConfig(t *testing.T) {
+ log.SetLoggerConfig(log.LoggerConfig{
+ Level: "trace",
+ Format: "text",
+ Output: "console",
+ })
+ config := log.GetLoggerConfig()
+ fmt.Printf("config=%v\n", config)
+ log.Trace("Something very low level.")
+ log.Debug("Useful debugging information.")
+ log.Info("Something noteworthy happened!")
+}
+
+func TestLog(t *testing.T) {
+ log.Trace("Something very low level.")
+ log.Tracef("Something very low level. %s", "test")
+ log.Traceln("Something very low level.")
+
+ log.Debug("Useful debugging information.")
+ log.Debugf("Useful debugging information. %s", "test")
+ log.Debugln("Useful debugging information.")
+
+ log.Info("Something noteworthy happened!")
+ log.Infof("Something noteworthy happened! %s", "test")
+ log.Infoln("Something noteworthy happened!")
+
+ log.Notice("Something unusual happened.")
+ log.Noticef("Something unusual happened. %s", "test")
+ log.Noticef("Something unusual happened.")
+
+ log.Warn("You should probably take a look at this.")
+ log.Warnf("You should probably take a look at this. %s", "test")
+ log.Warnln("You should probably take a look at this.")
+
+ log.Error("Something failed but I'm not quitting.")
+ log.Errorf("Something failed but I'm not quitting. %s", "test")
+ log.Errorln("Something failed but I'm not quitting.")
+
+ // Calls os.Exit(1) after logging
+ log.Fatal("Bye.")
+ log.Fatalf("Bye. %s", "test")
+ log.Fatalln("Bye.")
+
+ // Calls panic() after logging
+ log.Panic("I'm bailing.")
+ log.Panicf("I'm bailing. %s", "test")
+ log.Panicln("I'm bailing.")
+
+}
diff --git a/example/xml_test.go b/example/xml_test.go
new file mode 100644
index 0000000..9a1aa48
--- /dev/null
+++ b/example/xml_test.go
@@ -0,0 +1,172 @@
+package example
+
+import (
+ "encoding/xml"
+ "fmt"
+ "github.com/beevik/etree"
+ xmlUtil "github.com/wegoteam/wepkg/io/xml"
+ "log"
+ "os"
+ "strings"
+ "testing"
+)
+
+type Animal int
+type Size int
+
+const (
+ Unknown Animal = iota
+ Gopher
+ Zebra
+)
+const (
+ Unrecognized Size = iota
+ Small
+ Large
+)
+
+func (a *Animal) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ var s string
+ if err := d.DecodeElement(&s, &start); err != nil {
+ return err
+ }
+ switch strings.ToLower(s) {
+ default:
+ *a = Unknown
+ case "gopher":
+ *a = Gopher
+ case "zebra":
+ *a = Zebra
+ }
+
+ return nil
+}
+
+func (a Animal) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ var s string
+ switch a {
+ default:
+ s = "unknown"
+ case Gopher:
+ s = "gopher"
+ case Zebra:
+ s = "zebra"
+ }
+ return e.EncodeElement(s, start)
+}
+
+func (s *Size) UnmarshalText(text []byte) error {
+ switch strings.ToLower(string(text)) {
+ default:
+ *s = Unrecognized
+ case "small":
+ *s = Small
+ case "large":
+ *s = Large
+ }
+ return nil
+}
+
+func (s Size) MarshalText() ([]byte, error) {
+ var name string
+ switch s {
+ default:
+ name = "unrecognized"
+ case Small:
+ name = "small"
+ case Large:
+ name = "large"
+ }
+ return []byte(name), nil
+}
+
+func TestName(t *testing.T) {
+ blob := `
+
+ gopher
+ armadillo
+ zebra
+ unknown
+ gopher
+ bee
+ gopher
+ zebra
+ `
+ var zoo struct {
+ Animals []Animal `xml:"animal"`
+ }
+ if err := xml.Unmarshal([]byte(blob), &zoo); err != nil {
+ log.Fatal(err)
+ }
+
+ census := make(map[Animal]int)
+ for _, animal := range zoo.Animals {
+ census[animal] += 1
+ }
+
+ fmt.Printf("Zoo Census:\n* Gophers: %d\n* Zebras: %d\n* Unknown: %d\n",
+ census[Gopher], census[Zebra], census[Unknown])
+
+ blob2 := `
+
+ small
+ regular
+ large
+ unrecognized
+ small
+ normal
+ small
+ large
+ `
+ var inventory struct {
+ Sizes []Size `xml:"size"`
+ }
+ if err := xml.Unmarshal([]byte(blob2), &inventory); err != nil {
+ log.Fatal(err)
+ }
+
+ counts := make(map[Size]int)
+ for _, size := range inventory.Sizes {
+ counts[size] += 1
+ }
+
+ fmt.Printf("Inventory Counts:\n* Small: %d\n* Large: %d\n* Unrecognized: %d\n",
+ counts[Small], counts[Large], counts[Unrecognized])
+
+}
+
+func TestXML(t *testing.T) {
+ type User struct {
+ Name string `json:"name" xml:"name"`
+ }
+ var user User
+ user.Name = "test"
+ marshal, err := xmlUtil.Marshal(user)
+ if err != nil {
+ fmt.Errorf("xml.Marshal err: %v", err)
+ }
+ fmt.Println(marshal)
+
+ err = xmlUtil.Unmarshal(marshal, &user)
+ if err != nil {
+ fmt.Errorf("xml.Unmarshal err: %v", err)
+ }
+ fmt.Println(user)
+}
+func TestDocument(t *testing.T) {
+ doc := etree.NewDocument()
+ doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
+ doc.CreateProcInst("xml-stylesheet", `type="text/xsl" href="style.xsl"`)
+
+ people := doc.CreateElement("People")
+ people.CreateComment("These are all known people")
+
+ jon := people.CreateElement("Person")
+ jon.CreateAttr("name", "Jon")
+
+ sally := people.CreateElement("Person")
+ sally.CreateAttr("name", "Sally")
+
+ doc.Indent(2)
+ doc.WriteTo(os.Stdout)
+}
diff --git a/go.mod b/go.mod
index 92fcf4a..ca09478 100644
--- a/go.mod
+++ b/go.mod
@@ -7,50 +7,48 @@ require github.com/go-resty/resty/v2 v2.7.0
require gopkg.in/jeevatkm/go-model.v1 v1.1.0
require (
+ github.com/beevik/etree v1.2.0
+ github.com/bytedance/sonic v1.9.2
github.com/golang-module/carbon/v2 v2.2.3
github.com/golang-module/dongle v0.2.8
github.com/golang/snappy v0.0.4
github.com/google/uuid v1.3.0
- github.com/gookit/slog v0.5.1
+ github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
github.com/oklog/ulid v1.3.1
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.0.3
- github.com/rs/zerolog v1.29.1
+ github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.9.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
- go.uber.org/zap v1.21.0
+ gopkg.in/natefinch/lumberjack.v2 v2.2.1
gorm.io/gorm v1.25.1
)
require (
- github.com/bytedance/sonic v1.9.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emmansun/gmsm v0.19.1 // indirect
+ github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
- github.com/gookit/color v1.5.3 // indirect
- github.com/gookit/goutil v0.6.8 // indirect
- github.com/gookit/gsr v0.0.8 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
+ github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
+ github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
+ github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 // indirect
+ github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/magiconair/properties v1.8.7 // indirect
- github.com/mattn/go-colorable v0.1.12 // indirect
- github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
+ github.com/tebeka/strftime v0.1.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
- github.com/valyala/bytebufferpool v1.0.0 // indirect
- github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
- go.uber.org/atomic v1.9.0 // indirect
- go.uber.org/multierr v1.8.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
diff --git a/go.sum b/go.sum
index 8471f8d..e308a80 100644
--- a/go.sum
+++ b/go.sum
@@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
-github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
-github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
+github.com/beevik/etree v1.2.0 h1:l7WETslUG/T+xOPs47dtd6jov2Ii/8/OjCldk5fYfQw=
+github.com/beevik/etree v1.2.0/go.mod h1:aiPf89g/1k3AShMVAzriilpcE4R/Vuor90y83zVZWFc=
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
@@ -58,7 +58,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
-github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -73,6 +72,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU=
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
@@ -81,7 +82,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
-github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-module/carbon/v2 v2.2.3 h1:WvGIc5+qzq9drNzH+Gnjh1TZ0JgDY/IA+m2Dvk7Qm4Q=
github.com/golang-module/carbon/v2 v2.2.3/go.mod h1:LdzRApgmDT/wt0eNT8MEJbHfJdSqCtT46uZhfF30dqI=
github.com/golang-module/dongle v0.2.8 h1:AcoquGAfoLjSlw1w9pglBziw5HvNbtd1B4XVjK10Hh0=
@@ -145,24 +145,20 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
-github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
-github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
-github.com/gookit/goutil v0.6.8 h1:B2XXSCGav5TXWtKRT9i/s/owOLXXB7sY6UsfqeSLroE=
-github.com/gookit/goutil v0.6.8/go.mod h1:u+Isykc6RQcZ4GQzulsaGm+Famd97U5Tzp3aQyo+jyA=
-github.com/gookit/gsr v0.0.8 h1:zmkRYe4irObBAskD9UlZCRf8j5VwhhntlYQaSjrrUQk=
-github.com/gookit/gsr v0.0.8/go.mod h1:Q3CLTuluDDyk9/Du6xM721lG9/LQ3ywZde9bjmHyWA8=
-github.com/gookit/slog v0.5.1 h1:Df5PTYLT+a1y3eXqMZzK/AWBMkUIasgndeboUY1thGE=
-github.com/gookit/slog v0.5.1/go.mod h1:b4Z2URWbEyYa5xge4RfFAIVinhj2aVEZ9r5O9gL8SJ8=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
+github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
+github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -175,19 +171,20 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 h1:0iQektZGS248WXmGIYOwRXSQhD4qn3icjMpuxwO7qlo=
+github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE=
+github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgUSP4zdTUZYZgAGGtN5Lxk92rK+JUFOwf+FT99EEI4=
+github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8=
+github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc=
+github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
-github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
-github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
-github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
-github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
@@ -196,11 +193,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k=
github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
+github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
+github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
-github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
-github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
-github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
@@ -217,7 +213,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -228,17 +223,14 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
+github.com/tebeka/strftime v0.1.5 h1:1NQKN1NiQgkqd/2moD6ySP/5CoZQsKa1d3ZhJ44Jpmg=
+github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
-github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
@@ -246,16 +238,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
-go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
-go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
-go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
-go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
-go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
-go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
-go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
-go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
-go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
-go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -279,7 +261,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
-golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -303,7 +284,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -337,7 +317,6 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@@ -365,9 +344,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -401,13 +378,9 @@ golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -486,7 +459,6 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
-golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -589,11 +561,10 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/jeevatkm/go-model.v1 v1.1.0 h1:amtTNQLfoLEE35aUWKVI0plheGTHnlOnESGmN+dnTkA=
gopkg.in/jeevatkm/go-model.v1 v1.1.0/go.mod h1:DBVmvWau/0RaL6rFQeTiDcGn3u8xv5rTxKjDw2sIwmA=
+gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
+gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
-gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
diff --git a/io/xml/fromat.go b/io/xml/fromat.go
new file mode 100644
index 0000000..9fec8ca
--- /dev/null
+++ b/io/xml/fromat.go
@@ -0,0 +1,24 @@
+package xml
+
+//https://github.com/beevik/etree
+
+import "encoding/xml"
+
+// Marshal
+// @Description: 序列化
+// @param: val
+// @return string
+// @return error
+func Marshal(val any) (string, error) {
+ marshal, err := xml.Marshal(val)
+ return string(marshal), err
+}
+
+// Unmarshal
+// @Description: 反序列化
+// @param: buf
+// @param: val
+// @return error
+func Unmarshal(buf string, val any) error {
+ return xml.Unmarshal([]byte(buf), val)
+}
diff --git a/cron/cron.go b/job/cron/cron.go
similarity index 100%
rename from cron/cron.go
rename to job/cron/cron.go
diff --git a/job/xxljob/xxljob.go b/job/xxljob/xxljob.go
new file mode 100644
index 0000000..265311f
--- /dev/null
+++ b/job/xxljob/xxljob.go
@@ -0,0 +1,3 @@
+package xxljob
+
+//https://github.com/wego-xuchang/xxl-job-executor-go/blob/master/executor.go
diff --git a/lock/distributedlock/redislock.go b/lock/rlock/redislock.go
similarity index 71%
rename from lock/distributedlock/redislock.go
rename to lock/rlock/redislock.go
index e6eb494..144614d 100644
--- a/lock/distributedlock/redislock.go
+++ b/lock/rlock/redislock.go
@@ -1,17 +1,19 @@
-package distributedlock
+package rlock
+
+// redis分布式锁
+// https://github.com/bsm/redislock
+// https://github.com/go-redsync/redsync
//import (
-// "context"
// "fmt"
-// "github.com/bsm/redislock"
-// "github.com/redis/go-redis/v9"
// "log"
// "time"
+//
+// "github.com/bsm/redislock"
+// "github.com/redis/go-redis/v9"
//)
-///**
-//https://github.com/bsm/redislock
-// */
-//func Lock() {
+//
+//func main() {
// // Connect to redis.
// client := redis.NewClient(&redis.Options{
// Network: "tcp",
@@ -22,10 +24,8 @@ package distributedlock
// // Create a new lock client.
// locker := redislock.New(client)
//
-// ctx := context.Background()
-//
// // Try to obtain lock.
-// lock, err := locker.Obtain(ctx, "my-key", 100*time.Millisecond, nil)
+// lock, err := locker.Obtain("my-key", 100*time.Millisecond, nil)
// if err == redislock.ErrNotObtained {
// fmt.Println("Could not obtain lock!")
// } else if err != nil {
@@ -33,27 +33,28 @@ package distributedlock
// }
//
// // Don't forget to defer Release.
-// defer lock.Release(ctx)
+// defer lock.Release()
// fmt.Println("I have a lock!")
//
// // Sleep and check the remaining TTL.
// time.Sleep(50 * time.Millisecond)
-// if ttl, err := lock.TTL(ctx); err != nil {
+// if ttl, err := lock.TTL(); err != nil {
// log.Fatalln(err)
// } else if ttl > 0 {
// fmt.Println("Yay, I still have my lock!")
// }
//
// // Extend my lock.
-// if err := lock.Refresh(ctx, 100*time.Millisecond, nil); err != nil {
+// if err := lock.Refresh(100*time.Millisecond, nil); err != nil {
// log.Fatalln(err)
// }
//
// // Sleep a little longer, then check.
// time.Sleep(100 * time.Millisecond)
-// if ttl, err := lock.TTL(ctx); err != nil {
+// if ttl, err := lock.TTL(); err != nil {
// log.Fatalln(err)
// } else if ttl == 0 {
// fmt.Println("Now, my lock has expired!")
// }
+//
//}
diff --git a/log/log_test.go b/log/log_test.go
deleted file mode 100644
index ca56014..0000000
--- a/log/log_test.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package log
-
-import "testing"
-
-func TestName(t *testing.T) {
-
-}
diff --git a/log/logrus-logger.go b/log/logrus-logger.go
deleted file mode 100644
index ee62a00..0000000
--- a/log/logrus-logger.go
+++ /dev/null
@@ -1,62 +0,0 @@
-package log
-
-import (
- "context"
- "github.com/sirupsen/logrus"
- "os"
-)
-
-type LogrusLogger struct {
- logger *logrus.Logger
- ctx context.Context
-}
-
-func NewLogrusLogger(ctx context.Context) *LogrusLogger {
- logger := logrus.New()
- logger.Out = os.Stdout
- return &LogrusLogger{logger: logger, ctx: ctx}
-}
-
-func (l *LogrusLogger) Debugf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *LogrusLogger) Infof(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *LogrusLogger) Warnf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *LogrusLogger) Errorf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *LogrusLogger) Fatalf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *LogrusLogger) Debug(field ...interface{}) {
-
- l.logger.Debug(field)
-}
-
-func (l *LogrusLogger) Info(field ...interface{}) {
- l.logger.Info(field)
-}
-
-func (l *LogrusLogger) Warn(field ...interface{}) {
- l.logger.Warn(field)
-}
-func (l *LogrusLogger) Error(field ...interface{}) {
- l.logger.Error(field)
-}
-func (l *LogrusLogger) Fatal(field ...interface{}) {
- l.logger.Fatal(field)
-}
diff --git a/log/logrus/logrus.go b/log/logrus/logrus.go
new file mode 100644
index 0000000..2daea4b
--- /dev/null
+++ b/log/logrus/logrus.go
@@ -0,0 +1,148 @@
+package logrus
+
+import (
+ "context"
+ "github.com/wegoteam/wepkg/log/wlog"
+ "io"
+
+ "github.com/sirupsen/logrus"
+)
+
+var _ wlog.FullLogger = (*Logger)(nil)
+
+// Logger logrus impl
+type Logger struct {
+ l *logrus.Logger
+}
+
+// NewLogger create a logger
+func NewLogger(opts ...Option) *Logger {
+ cfg := defaultConfig()
+
+ // apply options
+ for _, opt := range opts {
+ opt.apply(cfg)
+ }
+
+ // attach hook
+ for _, hook := range cfg.hooks {
+ cfg.logger.AddHook(hook)
+ }
+
+ return &Logger{
+ l: cfg.logger,
+ }
+}
+
+func (l *Logger) Logger() *logrus.Logger {
+ return l.l
+}
+
+func (l *Logger) Trace(v ...interface{}) {
+ l.l.Trace(v...)
+}
+
+func (l *Logger) Debug(v ...interface{}) {
+ l.l.Debug(v...)
+}
+
+func (l *Logger) Info(v ...interface{}) {
+ l.l.Info(v...)
+}
+
+func (l *Logger) Notice(v ...interface{}) {
+ l.l.Warn(v...)
+}
+
+func (l *Logger) Warn(v ...interface{}) {
+ l.l.Warn(v...)
+}
+
+func (l *Logger) Error(v ...interface{}) {
+ l.l.Error(v...)
+}
+
+func (l *Logger) Fatal(v ...interface{}) {
+ l.l.Fatal(v...)
+}
+
+func (l *Logger) Tracef(format string, v ...interface{}) {
+ l.l.Tracef(format, v...)
+}
+
+func (l *Logger) Debugf(format string, v ...interface{}) {
+ l.l.Debugf(format, v...)
+}
+
+func (l *Logger) Infof(format string, v ...interface{}) {
+ l.l.Infof(format, v...)
+}
+
+func (l *Logger) Noticef(format string, v ...interface{}) {
+ l.l.Warnf(format, v...)
+}
+
+func (l *Logger) Warnf(format string, v ...interface{}) {
+ l.l.Warnf(format, v...)
+}
+
+func (l *Logger) Errorf(format string, v ...interface{}) {
+ l.l.Errorf(format, v...)
+}
+
+func (l *Logger) Fatalf(format string, v ...interface{}) {
+ l.l.Fatalf(format, v...)
+}
+
+func (l *Logger) CtxTracef(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Tracef(format, v...)
+}
+
+func (l *Logger) CtxDebugf(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Debugf(format, v...)
+}
+
+func (l *Logger) CtxInfof(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Infof(format, v...)
+}
+
+func (l *Logger) CtxNoticef(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Warnf(format, v...)
+}
+
+func (l *Logger) CtxWarnf(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Warnf(format, v...)
+}
+
+func (l *Logger) CtxErrorf(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Errorf(format, v...)
+}
+
+func (l *Logger) CtxFatalf(ctx context.Context, format string, v ...interface{}) {
+ l.l.WithContext(ctx).Fatalf(format, v...)
+}
+
+func (l *Logger) SetLevel(level wlog.Level) {
+ var lv logrus.Level
+ switch level {
+ case wlog.LevelTrace:
+ lv = logrus.TraceLevel
+ case wlog.LevelDebug:
+ lv = logrus.DebugLevel
+ case wlog.LevelInfo:
+ lv = logrus.InfoLevel
+ case wlog.LevelWarn, wlog.LevelNotice:
+ lv = logrus.WarnLevel
+ case wlog.LevelError:
+ lv = logrus.ErrorLevel
+ case wlog.LevelFatal:
+ lv = logrus.FatalLevel
+ default:
+ lv = logrus.WarnLevel
+ }
+ l.l.SetLevel(lv)
+}
+
+func (l *Logger) SetOutput(writer io.Writer) {
+ l.l.SetOutput(writer)
+}
diff --git a/log/logrus/option.go b/log/logrus/option.go
new file mode 100644
index 0000000..025a661
--- /dev/null
+++ b/log/logrus/option.go
@@ -0,0 +1,47 @@
+package logrus
+
+import (
+ "github.com/sirupsen/logrus"
+)
+
+// Option logger options
+type Option interface {
+ apply(cfg *config)
+}
+
+type option func(cfg *config)
+
+func (fn option) apply(cfg *config) {
+ fn(cfg)
+}
+
+type config struct {
+ logger *logrus.Logger
+ hooks []logrus.Hook
+}
+
+func defaultConfig() *config {
+ // std logger
+ stdLogger := logrus.StandardLogger()
+ // default json format
+ stdLogger.SetFormatter(new(logrus.JSONFormatter))
+
+ return &config{
+ logger: logrus.StandardLogger(),
+ hooks: []logrus.Hook{},
+ }
+}
+
+// WithLogger configures logger
+func WithLogger(logger *logrus.Logger) Option {
+ return option(func(cfg *config) {
+ cfg.logger = logger
+ })
+}
+
+// WithHook configures logrus hook
+func WithHook(hook logrus.Hook) Option {
+ return option(func(cfg *config) {
+ cfg.hooks = append(cfg.hooks, hook)
+ })
+}
diff --git a/log/option.go b/log/option.go
new file mode 100644
index 0000000..388eea1
--- /dev/null
+++ b/log/option.go
@@ -0,0 +1,157 @@
+package log
+
+import (
+ "fmt"
+ "github.com/sirupsen/logrus"
+ "github.com/wegoteam/wepkg/bean"
+ "github.com/wegoteam/wepkg/config"
+ "gopkg.in/natefinch/lumberjack.v2"
+ "io"
+ "os"
+ "strings"
+ "sync"
+)
+
+// LoggerConfig
+// @Description:
+type LoggerConfig struct {
+ Format string `json:"format" yaml:"format"` //日志输出格式,可选项:json、text
+ Level string `json:"level" yaml:"level"` //日志级别,可选项:debug、info、warn、error、panic、fatal
+ Output string `json:"output" yaml:"output"` //日志输出位置,可选项:console、file;多个用逗号分隔
+ FileName string `json:"fileName" json:"fileName"` //日志文件名
+ MaxSize int `json:"maxSize" json:"maxSize"` //日志文件最大大小,单位:MB
+ MaxAge int `json:"maxAge" yaml:"maxAge"` //日志文件最大保存时间,单位:天
+ MaxBackups int `json:"maxBackups" yaml:"maxBackups"` //日志文件最大备份数量
+}
+
+var (
+ logger *logrus.Logger
+ loggerConfig *LoggerConfig
+ once sync.Once
+ mutex sync.Mutex
+)
+
+// init
+// @Description: 初始化日志
+func init() {
+ once.Do(func() {
+ // 读取配置文件
+ loggerConfig = getConfig()
+ // 设置日志配置
+ SetLoggerConfig(*loggerConfig)
+ })
+
+ //logier, err := rotatelogs.New(
+ // // 切割后日志文件名称
+ // "./log/log2.txt",
+ // //rotatelogs.WithLinkName(Current.LogDir), // 生成软链,指向最新日志文件
+ // rotatelogs.WithMaxAge(30*24*time.Hour), // 文件最大保存时间
+ // rotatelogs.WithRotationTime(24*time.Hour), // 日志切割时间间隔
+ // //rotatelogs.WithRotationCount(3),
+ // //rotatelogs.WithRotationTime(time.Minute), // 日志切割时间间隔
+ //)
+ //if err != nil {
+ // fmt.Errorf("config local file system logger error. %v", err)
+ //}
+ //lfHook := lfshook.NewHook(lfshook.WriterMap{
+ // logrus.InfoLevel: logier,
+ // logrus.FatalLevel: logier,
+ // logrus.DebugLevel: logier,
+ // logrus.WarnLevel: logier,
+ // logrus.ErrorLevel: logier,
+ // logrus.PanicLevel: logier,
+ //}, formatter)
+ //logger.AddHook(lfHook)
+}
+
+// SetLoggerConfig
+// @Description: 设置日志配置
+// @param: config
+func SetLoggerConfig(config LoggerConfig) {
+ mutex.Lock()
+ defer mutex.Unlock()
+ loggerConfig = &config
+ logger = logrus.New()
+ var formatter logrus.Formatter
+ if loggerConfig.Format == "json" {
+ formatter = &logrus.JSONFormatter{}
+ } else {
+ formatter = &logrus.TextFormatter{}
+ }
+ logger.SetFormatter(formatter)
+
+ switch loggerConfig.Level {
+ case "trace":
+ logger.SetLevel(logrus.TraceLevel)
+ case "debug":
+ logger.SetLevel(logrus.DebugLevel)
+ case "info":
+ logger.SetLevel(logrus.InfoLevel)
+ case "warn":
+ logger.SetLevel(logrus.WarnLevel)
+ case "error":
+ logger.SetLevel(logrus.ErrorLevel)
+ case "panic":
+ logger.SetLevel(logrus.PanicLevel)
+ case "fatal":
+ logger.SetLevel(logrus.FatalLevel)
+ default:
+ logger.SetLevel(logrus.InfoLevel)
+ }
+
+ var writers = make([]io.Writer, 0)
+ output := loggerConfig.Output
+ if strings.Contains(output, "console") {
+ writers = append(writers, os.Stdout)
+ }
+ if strings.Contains(output, "file") {
+ writers = append(writers, &lumberjack.Logger{
+ Filename: loggerConfig.FileName,
+ MaxSize: loggerConfig.MaxSize,
+ MaxBackups: loggerConfig.MaxBackups,
+ MaxAge: loggerConfig.MaxAge,
+ LocalTime: true,
+ })
+ }
+ if len(writers) == 0 {
+ writers = append(writers, os.Stdout)
+ }
+ //同时写文件和屏幕
+ fileAndStdoutWriter := io.MultiWriter(writers...)
+ logger.SetOutput(fileAndStdoutWriter)
+ logger.SetReportCaller(true)
+}
+
+// GetLoggerConfig
+// @Description: 获取日志配置
+func GetLoggerConfig() *LoggerConfig {
+ return loggerConfig
+}
+
+// getConfig
+// @Description: 获取配置文件的配置
+// @return *LoggerConfig
+func getConfig() *LoggerConfig {
+ var logConfig = &LoggerConfig{}
+ c := config.GetConfig()
+ err := c.Load("logger", logConfig)
+ if err != nil {
+ fmt.Errorf("Fatal error config file: %s \n", err)
+ return &LoggerConfig{
+ Format: "text",
+ Level: "info",
+ Output: "console",
+ }
+ }
+ isNotExist := bean.IsZero(loggerConfig)
+ if isNotExist {
+ fmt.Errorf("Init logger config error use default config")
+ return &LoggerConfig{
+ Format: "text",
+ Level: "info",
+ Output: "console",
+ }
+ }
+ fmt.Printf("Init logger config: %v \n", logConfig)
+ return logConfig
+}
diff --git a/log/slog-logger.go b/log/slog-logger.go
deleted file mode 100644
index af1e8a0..0000000
--- a/log/slog-logger.go
+++ /dev/null
@@ -1,62 +0,0 @@
-package log
-
-import (
- "context"
- "github.com/gookit/slog"
-)
-
-type SlogLogger struct {
- logger *slog.SugaredLogger
- ctx context.Context
-}
-
-func NewSlogLogger(ctx context.Context) *SlogLogger {
- slog.Configure(func(logger *slog.SugaredLogger) {
- f := logger.Formatter.(*slog.TextFormatter)
- f.EnableColor = true
- })
- return &SlogLogger{logger: slog.Std(), ctx: ctx}
-}
-
-func (l *SlogLogger) Debugf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *SlogLogger) Infof(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *SlogLogger) Warnf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *SlogLogger) Errorf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *SlogLogger) Fatalf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *SlogLogger) Debug(field ...interface{}) {
- slog.Debug(field)
-}
-
-func (l *SlogLogger) Info(field ...interface{}) {
- slog.Info(field)
-}
-
-func (l *SlogLogger) Warn(field ...interface{}) {
- slog.Warn(field)
-}
-func (l *SlogLogger) Error(field ...interface{}) {
- slog.Error(field)
-}
-func (l *SlogLogger) Fatal(field ...interface{}) {
- slog.Fatal(field)
-}
diff --git a/log/wlog/consts.go b/log/wlog/consts.go
new file mode 100644
index 0000000..c10ada4
--- /dev/null
+++ b/log/wlog/consts.go
@@ -0,0 +1,7 @@
+package wlog
+
+const (
+ systemLogPrefix = "LOG: "
+
+ EngineErrorFormat = "Error=%s, remoteAddr=%s"
+)
diff --git a/log/wlog/default.go b/log/wlog/default.go
new file mode 100644
index 0000000..03b44f8
--- /dev/null
+++ b/log/wlog/default.go
@@ -0,0 +1,228 @@
+package wlog
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "log"
+ "os"
+)
+
+// Fatal calls the default logger's Fatal method and then os.Exit(1).
+func Fatal(v ...interface{}) {
+ logger.Fatal(v...)
+}
+
+// Error calls the default logger's Error method.
+func Error(v ...interface{}) {
+ logger.Error(v...)
+}
+
+// Warn calls the default logger's Warn method.
+func Warn(v ...interface{}) {
+ logger.Warn(v...)
+}
+
+// Notice calls the default logger's Notice method.
+func Notice(v ...interface{}) {
+ logger.Notice(v...)
+}
+
+// Info calls the default logger's Info method.
+func Info(v ...interface{}) {
+ logger.Info(v...)
+}
+
+// Debug calls the default logger's Debug method.
+func Debug(v ...interface{}) {
+ logger.Debug(v...)
+}
+
+// Trace calls the default logger's Trace method.
+func Trace(v ...interface{}) {
+ logger.Trace(v...)
+}
+
+// Fatalf calls the default logger's Fatalf method and then os.Exit(1).
+func Fatalf(format string, v ...interface{}) {
+ logger.Fatalf(format, v...)
+}
+
+// Errorf calls the default logger's Errorf method.
+func Errorf(format string, v ...interface{}) {
+ logger.Errorf(format, v...)
+}
+
+// Warnf calls the default logger's Warnf method.
+func Warnf(format string, v ...interface{}) {
+ logger.Warnf(format, v...)
+}
+
+// Noticef calls the default logger's Noticef method.
+func Noticef(format string, v ...interface{}) {
+ logger.Noticef(format, v...)
+}
+
+// Infof calls the default logger's Infof method.
+func Infof(format string, v ...interface{}) {
+ logger.Infof(format, v...)
+}
+
+// Debugf calls the default logger's Debugf method.
+func Debugf(format string, v ...interface{}) {
+ logger.Debugf(format, v...)
+}
+
+// Tracef calls the default logger's Tracef method.
+func Tracef(format string, v ...interface{}) {
+ logger.Tracef(format, v...)
+}
+
+// CtxFatalf calls the default logger's CtxFatalf method and then os.Exit(1).
+func CtxFatalf(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxFatalf(ctx, format, v...)
+}
+
+// CtxErrorf calls the default logger's CtxErrorf method.
+func CtxErrorf(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxErrorf(ctx, format, v...)
+}
+
+// CtxWarnf calls the default logger's CtxWarnf method.
+func CtxWarnf(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxWarnf(ctx, format, v...)
+}
+
+// CtxNoticef calls the default logger's CtxNoticef method.
+func CtxNoticef(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxNoticef(ctx, format, v...)
+}
+
+// CtxInfof calls the default logger's CtxInfof method.
+func CtxInfof(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxInfof(ctx, format, v...)
+}
+
+// CtxDebugf calls the default logger's CtxDebugf method.
+func CtxDebugf(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxDebugf(ctx, format, v...)
+}
+
+// CtxTracef calls the default logger's CtxTracef method.
+func CtxTracef(ctx context.Context, format string, v ...interface{}) {
+ logger.CtxTracef(ctx, format, v...)
+}
+
+type defaultLogger struct {
+ stdlog *log.Logger
+ level Level
+ depth int
+}
+
+func (ll *defaultLogger) SetOutput(w io.Writer) {
+ ll.stdlog.SetOutput(w)
+}
+
+func (ll *defaultLogger) SetLevel(lv Level) {
+ ll.level = lv
+}
+
+func (ll *defaultLogger) logf(lv Level, format *string, v ...interface{}) {
+ if ll.level > lv {
+ return
+ }
+ msg := lv.toString()
+ if format != nil {
+ msg += fmt.Sprintf(*format, v...)
+ } else {
+ msg += fmt.Sprint(v...)
+ }
+ ll.stdlog.Output(ll.depth, msg)
+ if lv == LevelFatal {
+ os.Exit(1)
+ }
+}
+
+func (ll *defaultLogger) Fatal(v ...interface{}) {
+ ll.logf(LevelFatal, nil, v...)
+}
+
+func (ll *defaultLogger) Error(v ...interface{}) {
+ ll.logf(LevelError, nil, v...)
+}
+
+func (ll *defaultLogger) Warn(v ...interface{}) {
+ ll.logf(LevelWarn, nil, v...)
+}
+
+func (ll *defaultLogger) Notice(v ...interface{}) {
+ ll.logf(LevelNotice, nil, v...)
+}
+
+func (ll *defaultLogger) Info(v ...interface{}) {
+ ll.logf(LevelInfo, nil, v...)
+}
+
+func (ll *defaultLogger) Debug(v ...interface{}) {
+ ll.logf(LevelDebug, nil, v...)
+}
+
+func (ll *defaultLogger) Trace(v ...interface{}) {
+ ll.logf(LevelTrace, nil, v...)
+}
+
+func (ll *defaultLogger) Fatalf(format string, v ...interface{}) {
+ ll.logf(LevelFatal, &format, v...)
+}
+
+func (ll *defaultLogger) Errorf(format string, v ...interface{}) {
+ ll.logf(LevelError, &format, v...)
+}
+
+func (ll *defaultLogger) Warnf(format string, v ...interface{}) {
+ ll.logf(LevelWarn, &format, v...)
+}
+
+func (ll *defaultLogger) Noticef(format string, v ...interface{}) {
+ ll.logf(LevelNotice, &format, v...)
+}
+
+func (ll *defaultLogger) Infof(format string, v ...interface{}) {
+ ll.logf(LevelInfo, &format, v...)
+}
+
+func (ll *defaultLogger) Debugf(format string, v ...interface{}) {
+ ll.logf(LevelDebug, &format, v...)
+}
+
+func (ll *defaultLogger) Tracef(format string, v ...interface{}) {
+ ll.logf(LevelTrace, &format, v...)
+}
+
+func (ll *defaultLogger) CtxFatalf(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelFatal, &format, v...)
+}
+
+func (ll *defaultLogger) CtxErrorf(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelError, &format, v...)
+}
+
+func (ll *defaultLogger) CtxWarnf(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelWarn, &format, v...)
+}
+
+func (ll *defaultLogger) CtxNoticef(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelNotice, &format, v...)
+}
+
+func (ll *defaultLogger) CtxInfof(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelInfo, &format, v...)
+}
+
+func (ll *defaultLogger) CtxDebugf(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelDebug, &format, v...)
+}
+
+func (ll *defaultLogger) CtxTracef(ctx context.Context, format string, v ...interface{}) {
+ ll.logf(LevelTrace, &format, v...)
+}
diff --git a/log/wlog/log.go b/log/wlog/log.go
new file mode 100644
index 0000000..b735a54
--- /dev/null
+++ b/log/wlog/log.go
@@ -0,0 +1,88 @@
+package wlog
+
+import (
+ "context"
+ "fmt"
+ "io"
+)
+
+// FormatLogger is a logger interface that output logs with a format.
+type FormatLogger interface {
+ Tracef(format string, v ...interface{})
+ Debugf(format string, v ...interface{})
+ Infof(format string, v ...interface{})
+ Noticef(format string, v ...interface{})
+ Warnf(format string, v ...interface{})
+ Errorf(format string, v ...interface{})
+ Fatalf(format string, v ...interface{})
+}
+
+// Logger is a logger interface that provides logging function with levels.
+type Logger interface {
+ Trace(v ...interface{})
+ Debug(v ...interface{})
+ Info(v ...interface{})
+ Notice(v ...interface{})
+ Warn(v ...interface{})
+ Error(v ...interface{})
+ Fatal(v ...interface{})
+}
+
+// CtxLogger is a logger interface that accepts a context argument and output
+// logs with a format.
+type CtxLogger interface {
+ CtxTracef(ctx context.Context, format string, v ...interface{})
+ CtxDebugf(ctx context.Context, format string, v ...interface{})
+ CtxInfof(ctx context.Context, format string, v ...interface{})
+ CtxNoticef(ctx context.Context, format string, v ...interface{})
+ CtxWarnf(ctx context.Context, format string, v ...interface{})
+ CtxErrorf(ctx context.Context, format string, v ...interface{})
+ CtxFatalf(ctx context.Context, format string, v ...interface{})
+}
+
+// Control provides methods to config a logger.
+type Control interface {
+ SetLevel(Level)
+ SetOutput(io.Writer)
+}
+
+// FullLogger is the combination of Logger, FormatLogger, CtxLogger and Control.
+type FullLogger interface {
+ Logger
+ FormatLogger
+ CtxLogger
+ Control
+}
+
+// Level defines the priority of a log message.
+// When a logger is configured with a level, any log message with a lower
+// log level (smaller by integer comparison) will not be output.
+type Level int
+
+// The levels of logs.
+const (
+ LevelTrace Level = iota
+ LevelDebug
+ LevelInfo
+ LevelNotice
+ LevelWarn
+ LevelError
+ LevelFatal
+)
+
+var strs = []string{
+ "[Trace] ",
+ "[Debug] ",
+ "[Info] ",
+ "[Notice] ",
+ "[Warn] ",
+ "[Error] ",
+ "[Fatal] ",
+}
+
+func (lv Level) toString() string {
+ if lv >= LevelTrace && lv <= LevelFatal {
+ return strs[lv]
+ }
+ return fmt.Sprintf("[?%d] ", lv)
+}
diff --git a/log/wlog/logger.go b/log/wlog/logger.go
new file mode 100644
index 0000000..3915895
--- /dev/null
+++ b/log/wlog/logger.go
@@ -0,0 +1,64 @@
+package wlog
+
+import (
+ "io"
+ "log"
+ "os"
+)
+
+var (
+ // Provide default logger for users to use
+ logger FullLogger = &defaultLogger{
+ stdlog: log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds),
+ depth: 4,
+ }
+
+ // Provide system logger for print system log
+ sysLogger FullLogger = &systemLogger{
+ &defaultLogger{
+ stdlog: log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds),
+ depth: 4,
+ },
+ systemLogPrefix,
+ }
+)
+
+// SetOutput sets the output of default logger and system logger. By default, it is stderr.
+func SetOutput(w io.Writer) {
+ logger.SetOutput(w)
+ sysLogger.SetOutput(w)
+}
+
+// SetLevel sets the level of logs below which logs will not be output.
+// The default logger and system logger level is LevelTrace.
+// Note that this method is not concurrent-safe.
+func SetLevel(lv Level) {
+ logger.SetLevel(lv)
+ sysLogger.SetLevel(lv)
+}
+
+// DefaultLogger return the default logger for hertz.
+func DefaultLogger() FullLogger {
+ return logger
+}
+
+// SystemLogger return the system logger for hertz to print system log.
+// This function is not recommended for users to use.
+func SystemLogger() FullLogger {
+ return sysLogger
+}
+
+// SetSystemLogger sets the system logger.
+// Note that this method is not concurrent-safe and must not be called
+// This function is not recommended for users to use.
+func SetSystemLogger(v FullLogger) {
+ sysLogger = &systemLogger{v, systemLogPrefix}
+}
+
+// SetLogger sets the default logger and the system logger.
+// Note that this method is not concurrent-safe and must not be called
+// after the use of DefaultLogger and global functions in this package.
+func SetLogger(v FullLogger) {
+ logger = v
+ SetSystemLogger(v)
+}
diff --git a/log/wlog/system.go b/log/wlog/system.go
new file mode 100644
index 0000000..988749a
--- /dev/null
+++ b/log/wlog/system.go
@@ -0,0 +1,139 @@
+package wlog
+
+import (
+ "context"
+ "io"
+ "strings"
+ "sync"
+)
+
+var silentMode = false
+
+// SetSilentMode is used to mute engine error log,
+// for example: error when reading request headers.
+// If true, hertz engine will mute it.
+func SetSilentMode(s bool) {
+ silentMode = s
+}
+
+var builderPool = sync.Pool{New: func() interface{} {
+ return &strings.Builder{} // nolint:SA6002
+}}
+
+type systemLogger struct {
+ logger FullLogger
+ prefix string
+}
+
+func (ll *systemLogger) SetOutput(w io.Writer) {
+ ll.logger.SetOutput(w)
+}
+
+func (ll *systemLogger) SetLevel(lv Level) {
+ ll.logger.SetLevel(lv)
+}
+
+func (ll *systemLogger) Fatal(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Fatal(v...)
+}
+
+func (ll *systemLogger) Error(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Error(v...)
+}
+
+func (ll *systemLogger) Warn(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Warn(v...)
+}
+
+func (ll *systemLogger) Notice(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Notice(v...)
+}
+
+func (ll *systemLogger) Info(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Info(v...)
+}
+
+func (ll *systemLogger) Debug(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Debug(v...)
+}
+
+func (ll *systemLogger) Trace(v ...interface{}) {
+ v = append([]interface{}{ll.prefix}, v...)
+ ll.logger.Trace(v...)
+}
+
+func (ll *systemLogger) Fatalf(format string, v ...interface{}) {
+ ll.logger.Fatalf(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Errorf(format string, v ...interface{}) {
+ if silentMode && format == EngineErrorFormat {
+ return
+ }
+ ll.logger.Errorf(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Warnf(format string, v ...interface{}) {
+ ll.logger.Warnf(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Noticef(format string, v ...interface{}) {
+ ll.logger.Noticef(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Infof(format string, v ...interface{}) {
+ ll.logger.Infof(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Debugf(format string, v ...interface{}) {
+ ll.logger.Debugf(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) Tracef(format string, v ...interface{}) {
+ ll.logger.Tracef(ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxFatalf(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxFatalf(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxErrorf(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxErrorf(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxWarnf(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxWarnf(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxNoticef(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxNoticef(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxInfof(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxInfof(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxDebugf(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxDebugf(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) CtxTracef(ctx context.Context, format string, v ...interface{}) {
+ ll.logger.CtxTracef(ctx, ll.addPrefix(format), v...)
+}
+
+func (ll *systemLogger) addPrefix(format string) string {
+ builder := builderPool.Get().(*strings.Builder)
+ builder.Grow(len(format) + len(ll.prefix))
+ builder.WriteString(ll.prefix)
+ builder.WriteString(format)
+ s := builder.String()
+ builder.Reset()
+ builderPool.Put(builder) // nolint:SA6002
+ return s
+}
diff --git a/log/zap-logger.go b/log/zap-logger.go
deleted file mode 100644
index 351a404..0000000
--- a/log/zap-logger.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package log
-
-import (
- "context"
- "go.uber.org/zap"
-)
-
-type ZapLogger struct {
- logger *zap.Logger
- ctx context.Context
-}
-
-func NewZapLog(ctx context.Context) *ZapLogger {
- logger, _ := zap.NewProduction()
- return &ZapLogger{logger: logger, ctx: ctx}
-}
-
-func (l *ZapLogger) Debugf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZapLogger) Infof(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZapLogger) Warnf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZapLogger) Errorf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZapLogger) Fatalf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZapLogger) Debug(field ...interface{}) {
- l.logger.Debug("", zap.Any("args", field))
-}
-
-func (l *ZapLogger) Info(field ...interface{}) {
- l.logger.Info("", zap.Any("args", field))
-}
-
-func (l *ZapLogger) Warn(field ...interface{}) {
- l.logger.Warn("", zap.Any("args", field))
-}
-func (l *ZapLogger) Error(field ...interface{}) {
- l.logger.Error("", zap.Any("args", field))
-}
-func (l *ZapLogger) Fatal(field ...interface{}) {
- l.logger.Fatal("", zap.Any("args", field))
-}
diff --git a/log/zerolog-logger.go b/log/zerolog-logger.go
deleted file mode 100644
index 5066667..0000000
--- a/log/zerolog-logger.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package log
-
-import (
- "context"
- "github.com/rs/zerolog"
- "os"
-)
-
-type ZeroLogger struct {
- logger *zerolog.Logger
- ctx context.Context
-}
-
-func NewZeroLogger(ctx context.Context) *ZeroLogger {
- zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
- zlogger := zerolog.New(os.Stderr).With().Timestamp().Logger()
-
- return &ZeroLogger{logger: &zlogger, ctx: ctx}
-}
-
-func (l *ZeroLogger) Debugf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZeroLogger) Infof(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZeroLogger) Warnf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZeroLogger) Errorf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZeroLogger) Fatalf(msg string, field ...interface{}) {
- //TODO implement me
- panic("implement me")
-}
-
-func (l *ZeroLogger) Debug(field ...interface{}) {
- l.logger.Debug().Msg("")
-}
-
-func (l *ZeroLogger) Info(field ...interface{}) {
-}
-
-func (l *ZeroLogger) Warn(field ...interface{}) {
-}
-func (l *ZeroLogger) Error(field ...interface{}) {
-}
-func (l *ZeroLogger) Fatal(field ...interface{}) {
-}
From 2498ec2ec1eba28ee0a4f3ce191b69e213ce24f5 Mon Sep 17 00:00:00 2001
From: xuchang <574616156@qq.com>
Date: Wed, 2 Aug 2023 19:12:17 +0800
Subject: [PATCH 4/4] =?UTF-8?q?v1.0.5=20http=E3=80=81config=E3=80=81json?=
=?UTF-8?q?=E3=80=81log=E3=80=81xml?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/log/log.txt | 149 -----------------------------
example/log/log2.txt | 13 ---
log/log.go | 217 ++++++++++++++++++++++++++++++++++---------
3 files changed, 174 insertions(+), 205 deletions(-)
delete mode 100644 example/log/log.txt
delete mode 100644 example/log/log2.txt
diff --git a/example/log/log.txt b/example/log/log.txt
deleted file mode 100644
index e0e906c..0000000
--- a/example/log/log.txt
+++ /dev/null
@@ -1,149 +0,0 @@
-time="2023-08-01T20:22:33+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-01T20:22:33+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-01T20:22:33+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-01T20:22:33+08:00" level=fatal msg=Bye.
-[36mINFO[0m[0000] Something noteworthy happened!
-[33mWARN[0m[0000] You should probably take a look at this.
-[31mERRO[0m[0000] Something failed but I'm not quitting.
-[31mFATA[0m[0000] Bye.
-time="2023-08-01T20:24:20+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-01T20:24:20+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-01T20:24:20+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-01T20:24:20+08:00" level=fatal msg=Bye.
-time="2023-08-02T08:57:44+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T08:57:44+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T08:57:44+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T08:57:44+08:00" level=fatal msg=Bye.
-time="2023-08-02T08:58:08+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T08:58:08+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T08:58:08+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T08:58:08+08:00" level=fatal msg=Bye.
-time="2023-08-02T08:58:50+08:00" level=trace msg="Something very low level."
-time="2023-08-02T08:58:50+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T08:58:50+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T08:58:50+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T08:58:50+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T08:58:50+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:28:48+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:28:48+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:28:48+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:28:48+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:28:48+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:28:48+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:29:03+08:00" level=trace msg="Something very low level. test"
-time="2023-08-02T09:29:03+08:00" level=debug msg="Useful debugging information. test"
-time="2023-08-02T09:29:03+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:29:03+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:29:03+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:29:03+08:00" level=fatal msg="Bye. test"
-time="2023-08-02T09:29:57+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:29:57+08:00" level=trace msg="Something very low level. test"
-time="2023-08-02T09:29:57+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:29:57+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:29:57+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:29:57+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:29:57+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level. test"
-time="2023-08-02T09:32:49+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information. test"
-time="2023-08-02T09:32:49+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:32:49+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:32:49+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:32:49+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:32:49+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level. test"
-time="2023-08-02T09:33:53+08:00" level=trace msg="Something very low level."
-time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information. test"
-time="2023-08-02T09:33:53+08:00" level=debug msg="Useful debugging information."
-time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:33:53+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:33:53+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:33:53+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:33:53+08:00" level=panic msg="I'm bailing."
-[36mINFO[0m[0000] Something noteworthy happened!
-[36mINFO[0m[0000] Something noteworthy happened! test
-[36mINFO[0m[0000] Something noteworthy happened!
-[33mWARN[0m[0000] You should probably take a look at this.
-[33mWARN[0m[0000] You should probably take a look at this. test
-[33mWARN[0m[0000] You should probably take a look at this.
-[31mERRO[0m[0000] Something failed but I'm not quitting.
-[31mERRO[0m[0000] Something failed but I'm not quitting. test
-[31mERRO[0m[0000] Something failed but I'm not quitting.
-[31mFATA[0m[0000] Bye.
-time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:37:38+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:37:38+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:37:38+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:37:38+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:45:58+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened."
-time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened. test"
-time="2023-08-02T09:45:58+08:00" level=warning msg="Something unusual happened."
-time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:45:58+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:45:58+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:45:58+08:00" level=fatal msg=Bye.
-time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened! test"
-time="2023-08-02T09:55:26+08:00" level=info msg="Something noteworthy happened!"
-time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened."
-time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened. test"
-time="2023-08-02T09:55:26+08:00" level=warning msg="Something unusual happened."
-time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this. test"
-time="2023-08-02T09:55:26+08:00" level=warning msg="You should probably take a look at this."
-time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting. test"
-time="2023-08-02T09:55:26+08:00" level=error msg="Something failed but I'm not quitting."
-time="2023-08-02T09:55:26+08:00" level=fatal msg=Bye.
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:84"
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:143"
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:204"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:91"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:98"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:159"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:218"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:105"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:167"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:225"
-time="2023-08-02T10:57:31+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:119"
-time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:21"
-time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:80"
-time="2023-08-02T17:42:21+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:141"
-time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:28"
-time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:88"
-time="2023-08-02T17:42:21+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:88"
-time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:35"
-time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:96"
-time="2023-08-02T17:42:21+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:155"
-time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:42"
-time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:104"
-time="2023-08-02T17:42:21+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:162"
-time="2023-08-02T17:42:21+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:56"
diff --git a/example/log/log2.txt b/example/log/log2.txt
deleted file mode 100644
index 5c39710..0000000
--- a/example/log/log2.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Info file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:84"
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened! test" func=github.com/wegoteam/wepkg/log.Infof file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:143"
-time="2023-08-02T10:57:31+08:00" level=info msg="Something noteworthy happened!" func=github.com/wegoteam/wepkg/log.Infoln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:204"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Notice file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:91"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened. test" func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
-time="2023-08-02T10:57:31+08:00" level=warning msg="Something unusual happened." func=github.com/wegoteam/wepkg/log.Noticef file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:151"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warn file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:98"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this. test" func=github.com/wegoteam/wepkg/log.Warnf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:159"
-time="2023-08-02T10:57:31+08:00" level=warning msg="You should probably take a look at this." func=github.com/wegoteam/wepkg/log.Warnln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:218"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Error file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:105"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting. test" func=github.com/wegoteam/wepkg/log.Errorf file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:167"
-time="2023-08-02T10:57:31+08:00" level=error msg="Something failed but I'm not quitting." func=github.com/wegoteam/wepkg/log.Errorln file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:225"
-time="2023-08-02T10:57:31+08:00" level=fatal msg=Bye. func=github.com/wegoteam/wepkg/log.Fatal file="/Users/xuchang/DevelopCode/wego/wepkg/log/log.go:119"
diff --git a/log/log.go b/log/log.go
index 1b3509a..981a72d 100644
--- a/log/log.go
+++ b/log/log.go
@@ -1,46 +1,177 @@
package log
-import (
- "context"
-)
-
-//https://github.com/uber-go/zap
-//https://github.com/Sirupsen/logrus
-//https://github.com/gookit/slog
-//https://github.com/rs/zerolog
-
-type LoggerWrapper struct {
- logger Logger
-}
-
-type Logger interface {
- Debug(field ...interface{})
- Info(field ...interface{})
- Warn(field ...interface{})
- Error(field ...interface{})
- Fatal(field ...interface{})
-
- Debugf(msg string, field ...interface{})
- Infof(msg string, field ...interface{})
- Warnf(msg string, field ...interface{})
- Errorf(msg string, field ...interface{})
- Fatalf(msg string, field ...interface{})
-}
-
-func NewLoggerWrapper(loggerType string, ctx context.Context) *LoggerWrapper {
- var logger Logger
-
- switch loggerType {
- case "logrus":
- logger = NewLogrusLogger(ctx)
- case "zap":
- logger = NewZapLog(ctx)
- case "zerolog":
- logger = NewZeroLogger(ctx)
- case "slog":
- logger = NewSlogLogger(ctx)
- default:
- logger = NewLogrusLogger(ctx)
- }
- return &LoggerWrapper{logger: logger}
+// Trace
+// @Description: 在标准日志记录器的Trace级别记录消息
+// @param: args
+func Trace(args ...interface{}) {
+ logger.Trace(args...)
+}
+
+// Debug
+// @Description: 在标准日志记录器的Debug级别记录消息
+// @param: args
+func Debug(args ...interface{}) {
+ logger.Debug(args...)
+}
+
+// Info
+// @Description: 在标准日志记录器的Info级别记录消息
+// @param: args
+func Info(args ...interface{}) {
+ logger.Info(args...)
+}
+
+// Notice
+// @Description: 在标准日志记录器的Notice级别记录消息
+// @param: args
+func Notice(args ...interface{}) {
+ logger.Warn(args...)
+}
+
+// Warn
+// @Description: 在标准日志记录器的Warn级别记录消息
+// @param: args
+func Warn(args ...interface{}) {
+ logger.Warn(args...)
+}
+
+// Error
+// @Description: 在标准日志记录器的Error级别记录消息
+// @param: args
+func Error(args ...interface{}) {
+ logger.Error(args...)
+}
+
+// Panic
+// @Description: 在标准日志记录器的Panic级别记录消息
+// @param: args
+func Panic(args ...interface{}) {
+ logger.Panic(args...)
+}
+
+// Fatal
+// @Description: Fatal在标准日志记录器上以Fatal级别记录消息,然后进程将退出并将状态设置为1
+// @param: args
+func Fatal(args ...interface{}) {
+ logger.Fatal(args...)
+}
+
+// Tracef
+// @Description: 在标准日志记录器的Trace级别记录格式化消息
+// @param: format
+// @param: args
+func Tracef(format string, args ...interface{}) {
+ logger.Tracef(format, args...)
+}
+
+// Debugf
+// @Description: 在标准日志记录器的Debug级别记录格式化消息
+// @param: format
+// @param: args
+func Debugf(format string, args ...interface{}) {
+ logger.Debugf(format, args...)
+}
+
+// Infof
+// @Description: 在标准日志记录器的Info级别记录格式化消息
+// @param: format
+// @param: args
+func Infof(format string, args ...interface{}) {
+ logger.Infof(format, args...)
+}
+
+// Noticef
+// @Description: 在标准日志记录器的Notice级别记录格式化消息
+// @param: format
+// @param: args
+func Noticef(format string, args ...interface{}) {
+ logger.Warnf(format, args...)
+}
+
+// Warnf
+// @Description: 在标准日志记录器的Warn级别记录格式化消息
+// @param: format
+// @param: args
+func Warnf(format string, args ...interface{}) {
+ logger.Warnf(format, args...)
+}
+
+// Errorf
+// @Description: 在标准日志记录器的Error级别记录格式化消息
+// @param: format
+// @param: args
+func Errorf(format string, args ...interface{}) {
+ logger.Errorf(format, args...)
+}
+
+// Panicf
+// @Description: 在标准日志记录器的Panic级别记录格式化消息
+// @param: format
+// @param: args
+func Panicf(format string, args ...interface{}) {
+ logger.Panicf(format, args...)
+}
+
+// Fatalf
+// @Description: Fatal在标准日志记录器上以Fatal级别记录格式化消息,然后进程将退出并将状态设置为1
+// @param: format
+// @param: args
+func Fatalf(format string, args ...interface{}) {
+ logger.Fatalf(format, args...)
+}
+
+// Traceln
+// @Description: 在标准日志记录器的Trace级别记录消息
+// @param: args
+func Traceln(args ...interface{}) {
+ logger.Traceln(args...)
+}
+
+// Debugln
+// @Description: 在标准日志记录器的Debug级别记录消息
+// @param: args
+func Debugln(args ...interface{}) {
+ logger.Debugln(args...)
+}
+
+// Infoln
+// @Description: 在标准日志记录器的Info级别记录消息
+// @param: args
+func Infoln(args ...interface{}) {
+ logger.Infoln(args...)
+}
+
+// Noticeln
+// @Description: 在标准日志记录器的Notice级别记录消息
+// @param: args
+func Noticeln(args ...interface{}) {
+ logger.Warnln(args...)
+}
+
+// Warnln
+// @Description: 在标准日志记录器的Warn级别记录消息
+// @param: args
+func Warnln(args ...interface{}) {
+ logger.Warnln(args...)
+}
+
+// Errorln
+// @Description: 在标准日志记录器的Error级别记录消息
+// @param: args
+func Errorln(args ...interface{}) {
+ logger.Errorln(args...)
+}
+
+// Panicln
+// @Description: 在标准日志记录器的Panic级别记录消息
+// @param: args
+func Panicln(args ...interface{}) {
+ logger.Panicln(args...)
+}
+
+// Fatalln
+// @Description: Fatal在标准日志记录器上以Fatal级别记录消息,然后进程将退出并将状态设置为1
+// @param: args
+func Fatalln(args ...interface{}) {
+ logger.Fatalln(args...)
}