diff --git a/.golangci.yaml b/.golangci.yaml index 241c58a..8b1c1db 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,11 +5,11 @@ run: linters-settings: gosimple: - go: "1.15" + go: "1.16" # https://staticcheck.io/docs/options#checks checks: [ "all" ] staticcheck: - go: "1.15" + go: "1.16" # https://staticcheck.io/docs/options#checks checks: [ "all", "-SA1019", "-SA5008" ] goconst: @@ -23,7 +23,7 @@ linters-settings: - appendAssign - ifElseChain gofumpt: - lang-version: "1.15" + lang-version: "1.16" # https://github.com/mvdan/gofumpt#gofumpt extra-rules: true revive: @@ -38,7 +38,7 @@ linters-settings: - name: errorf - name: blank-imports - name: context-as-argument - - name: dot-imports + # - name: dot-imports - name: error-return - name: error-strings - name: error-naming @@ -46,7 +46,7 @@ linters-settings: - name: if-return - name: increment-decrement # - name: var-naming - - name: package-comments + # - name: package-comments - name: range - name: receiver-naming - name: indent-error-flow @@ -61,7 +61,7 @@ linters: - govet - ineffassign - staticcheck - - structcheck + # - structcheck - typecheck - goconst - gocritic diff --git a/Makefile b/Makefile index b4cddb1..9b85e18 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ tidy: @go mod tidy -e -v fmt: - @find . -name '*.go' -not -path "./vendor/*" -not -name "*.pb.go" | xargs gofumpt -w -s -extra - @find . -name '*.go' -not -path "./vendor/*" -not -name "*.pb.go" | xargs -n 1 -I {} -t goimports-reviser -file-path {} -local "github.com/sliveryou" project-name "github.com/sliveryou/go-tool/" -rm-unused + @find . -name '*.go' -not -path "./vendor/*" | xargs gofumpt -w -extra + @find . -name '*.go' -not -path "./vendor/*" | xargs -n 1 -t goimports-reviser -rm-unused -set-alias -company-prefixes "github.com/sliveryou" -project-name "github.com/sliveryou/go-tool" @find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 2 -ci -bn -sr lint: diff --git a/README.md b/README.md index 04e42d6..5d4e61d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ [![Github Latest Tag](https://img.shields.io/github/tag/sliveryou/go-tool.svg?style=flat)](https://github.com/sliveryou/go-tool/tags) [![Github Stars](https://img.shields.io/github/stars/sliveryou/go-tool.svg?style=flat)](https://github.com/sliveryou/go-tool/stargazers) - go 常用工具函数集合 ## 简介 @@ -402,7 +401,6 @@ func Date(t time.Time, location ...*time.Location) string func DateTime(t time.Time, location ...*time.Location) string func DoCycleTask(ctx context.Context, f func(), d time.Duration) func Format(t time.Time, layout string, location ...*time.Location) string -func HongKong() *time.Location func Local() *time.Location func Location(name string) *time.Location func Now(location ...*time.Location) time.Time diff --git a/dep.sh b/dep.sh index 7f7192a..a740153 100644 --- a/dep.sh +++ b/dep.sh @@ -12,11 +12,11 @@ else download="go install" fi -${download} github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 -${download} golang.org/x/tools/cmd/goimports@v0.1.5 -${download} github.com/incu6us/goimports-reviser/v2@v2.4.4 -${download} mvdan.cc/gofumpt@v0.1.1 -${download} mvdan.cc/sh/v3/cmd/shfmt@v3.3.1 -${download} mvdan.cc/sh/v3/cmd/gosh@v3.3.1 +${download} github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 +${download} golang.org/x/tools/cmd/goimports@v0.16.1 +${download} github.com/incu6us/goimports-reviser/v3@v3.6.2 +${download} mvdan.cc/gofumpt@v0.5.0 +${download} mvdan.cc/sh/v3/cmd/shfmt@v3.7.0 +${download} mvdan.cc/sh/v3/cmd/gosh@v3.7.0 echo "done" diff --git a/go.mod b/go.mod index 37c7c6e..7e0ea31 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,13 @@ module github.com/sliveryou/go-tool -go 1.14 +go 1.16 require ( - github.com/go-playground/locales v0.14.0 - github.com/go-playground/universal-translator v0.18.0 - github.com/go-playground/validator/v10 v10.11.0 + github.com/go-playground/locales v0.14.1 + github.com/go-playground/universal-translator v0.18.1 + github.com/go-playground/validator/v10 v10.17.0 + github.com/kr/pretty v0.3.1 // indirect github.com/shopspring/decimal v1.3.1 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.4 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c ) diff --git a/go.sum b/go.sum index 65433ac..17a8296 100644 --- a/go.sum +++ b/go.sum @@ -2,54 +2,83 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 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= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= -github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw= -github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74= +github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 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/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +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.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/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/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 h1:siQdpVirKtzPhKl3lZWozZraCFObP8S1v6PRp0bLrtU= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/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-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +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= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -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= diff --git a/id-generator/uuid/satori/codec.go b/id-generator/uuid/satori/codec.go index cbf8c85..c23fb31 100644 --- a/id-generator/uuid/satori/codec.go +++ b/id-generator/uuid/satori/codec.go @@ -70,27 +70,30 @@ func (u UUID) MarshalText() (text []byte, err error) { // UnmarshalText implements the encoding.TextUnmarshaler interface. // Following formats are supported: -// "6ba7b810-9dad-11d1-80b4-00c04fd430c8", -// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", -// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" -// "6ba7b8109dad11d180b400c04fd430c8" +// +// "6ba7b810-9dad-11d1-80b4-00c04fd430c8", +// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", +// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" +// "6ba7b8109dad11d180b400c04fd430c8" +// // ABNF for supported UUID text representation follows: -// uuid := canonical | hashlike | braced | urn -// plain := canonical | hashlike -// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct -// hashlike := 12hexoct -// braced := '{' plain '}' -// urn := URN ':' UUID-NID ':' plain -// URN := 'urn' -// UUID-NID := 'uuid' -// 12hexoct := 6hexoct 6hexoct -// 6hexoct := 4hexoct 2hexoct -// 4hexoct := 2hexoct 2hexoct -// 2hexoct := hexoct hexoct -// hexoct := hexdig hexdig -// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | -// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | -// 'A' | 'B' | 'C' | 'D' | 'E' | 'F' +// +// uuid := canonical | hashlike | braced | urn +// plain := canonical | hashlike +// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct +// hashlike := 12hexoct +// braced := '{' plain '}' +// urn := URN ':' UUID-NID ':' plain +// URN := 'urn' +// UUID-NID := 'uuid' +// 12hexoct := 6hexoct 6hexoct +// 6hexoct := 4hexoct 2hexoct +// 4hexoct := 2hexoct 2hexoct +// 2hexoct := hexoct hexoct +// hexoct := hexdig hexdig +// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | +// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | +// 'A' | 'B' | 'C' | 'D' | 'E' | 'F' func (u *UUID) UnmarshalText(text []byte) (err error) { switch len(text) { case 32: diff --git a/id-generator/uuid/satori/uuid.go b/id-generator/uuid/satori/uuid.go index d95f649..cf23a15 100644 --- a/id-generator/uuid/satori/uuid.go +++ b/id-generator/uuid/satori/uuid.go @@ -152,6 +152,7 @@ func (u *UUID) SetVariant(v byte) { // Must is a helper that wraps a call to a function returning (UUID, error) // and panics if the error is non-nil. It is intended for use in variable // initializations such as +// // var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000")); func Must(u UUID, err error) UUID { if err != nil { diff --git a/mathx/mathx.go b/mathx/mathx.go index b20e024..4993f35 100644 --- a/mathx/mathx.go +++ b/mathx/mathx.go @@ -54,9 +54,10 @@ func RoundBankToString(f float64, places int) string { } // Sign returns: -// -1 if f < 0 -// 0 if f == 0 -// +1 if f > 0 +// +// -1 if f < 0 +// 0 if f == 0 +// +1 if f > 0 func Sign(f float64) int { if math.Float64bits(f) != 0 { if f > 0 { @@ -68,49 +69,55 @@ func Sign(f float64) int { } // IsPositive returns: -// true if d > 0 -// false if d == 0 -// false if d < 0 +// +// true if d > 0 +// false if d == 0 +// false if d < 0 func IsPositive(f float64) bool { return Sign(f) == 1 } // IsNonPositive returns: -// true if d < 0 -// true if d == 0 -// false if d > 0 +// +// true if d < 0 +// true if d == 0 +// false if d > 0 func IsNonPositive(f float64) bool { return Sign(f) == -1 || Sign(f) == 0 } // IsNegative returns: -// true if d < 0 -// false if d == 0 -// false if d > 0 +// +// true if d < 0 +// false if d == 0 +// false if d > 0 func IsNegative(f float64) bool { return Sign(f) == -1 } // IsNonNegative returns: -// true if d > 0 -// true if d == 0 -// false if d < 0 +// +// true if d > 0 +// true if d == 0 +// false if d < 0 func IsNonNegative(f float64) bool { return Sign(f) == 1 || Sign(f) == 0 } // IsZero returns: -// true if d == 0 -// false if d > 0 -// false if d < 0 +// +// true if d == 0 +// false if d > 0 +// false if d < 0 func IsZero(f float64) bool { return Sign(f) == 0 } // Compare compares f1 and f2 and returns: -// -1 if f1 < f2 -// 0 if | f1 - f2 | <= 10 ^ -places, default places is 9 -// +1 if f1 > f2 +// +// -1 if f1 < f2 +// 0 if | f1 - f2 | <= 10 ^ -places, default places is 9 +// +1 if f1 > f2 func Compare(f1, f2 float64, places ...int) int { pla := floatPlaces if len(places) != 0 && places[0] >= 1 { diff --git a/slicex/equal.go b/slicex/equal.go index 16ef07d..0eb9509 100644 --- a/slicex/equal.go +++ b/slicex/equal.go @@ -17,9 +17,8 @@ func Equal(arr1, arr2 interface{}) bool { return reflect.DeepEqual(arr1, arr2) } else if kind1 == reflect.Array && kind2 == reflect.Array { return arr1 == arr2 - } else { - panic("slicex: invalid arr1 or arr2 type") } + panic("slicex: invalid arr1 or arr2 type") } // EqualStrings reports whether string arr1 equals string arr2. diff --git a/timex/timex.go b/timex/timex.go index e56598c..b346c6a 100644 --- a/timex/timex.go +++ b/timex/timex.go @@ -9,17 +9,16 @@ import ( // time package variables. var ( - shanghai = Location("Asia/Shanghai") // Shanghai *time.Location - hongkong = Location("Asia/Hong_Kong") // Hong Kong *time.Location - local = Location("Local") // Local *time.Location - utc = Location("UTC") // UTC *time.Location + local = time.Local // Local *time.Location + utc = time.UTC // UTC *time.Location + shanghai = Location("Asia/Shanghai") // Shanghai *time.Location ) // Location returns *time.Location by location name. func Location(name string) *time.Location { loc, err := time.LoadLocation(name) if err != nil { - panic(err) + loc = time.Local } return loc } @@ -29,11 +28,6 @@ func Shanghai() *time.Location { return shanghai } -// HongKong returns Hong Kong *time.Location. -func HongKong() *time.Location { - return hongkong -} - // Local returns Local *time.Location. func Local() *time.Location { return local @@ -249,9 +243,10 @@ func SleepMicrosecond(n int64) { // StringToTime returns time.Time representation of str value parsed according to layout. // layout example: -// 20060102150405 -// 2006-01-02 15:04:05 -// 2006/01/02 15/04/05 +// +// 20060102150405 +// 2006-01-02 15:04:05 +// 2006/01/02 15/04/05 func StringToTime(str, layout string, location ...*time.Location) (time.Time, error) { loc := getLocation(location...) if len(str) != len(layout) { @@ -264,9 +259,10 @@ func StringToTime(str, layout string, location ...*time.Location) (time.Time, er // StringToUnix returns unix second timestamp representation of str value parsed according to layout. // If str parsed err, it returns now unix second timestamp. // layout example: -// 20060102150405 -// 2006-01-02 15:04:05 -// 2006/01/02 15/04/05 +// +// 20060102150405 +// 2006-01-02 15:04:05 +// 2006/01/02 15/04/05 func StringToUnix(str, layout string, location ...*time.Location) int64 { t, err := StringToTime(str, layout, location...) if err != nil { diff --git a/timex/timex_test.go b/timex/timex_test.go index c39628a..69deaff 100644 --- a/timex/timex_test.go +++ b/timex/timex_test.go @@ -20,9 +20,6 @@ func TestLocation(t *testing.T) { assertion.NotPanics(func() { Shanghai() }) - assertion.NotPanics(func() { - HongKong() - }) assertion.NotPanics(func() { Local() }) diff --git a/validator/validator.go b/validator/validator.go index 0719a50..5c11d15 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -8,7 +8,7 @@ import ( "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator" - "github.com/go-playground/validator/v10" + validator "github.com/go-playground/validator/v10" zht "github.com/go-playground/validator/v10/translations/zh" ) @@ -47,23 +47,23 @@ var ( "httpmethod": httpmethod, } defaultTags = []string{ - "excluded_if", - "excluded_unless", - "excluded_with", - "excluded_with_all", - "excluded_without", - "excluded_without_all", - "isdefault", + "skip_unless", + "eq_ignore_case", + "ne_ignore_case", "fieldcontains", "fieldexcludes", "boolean", "e164", + "http_url", "urn_rfc2141", "file", + "filepath", "base64url", + "base64rawurl", "startsnotwith", "endsnotwith", "eth_addr", + "eth_addr_checksum", "btc_addr", "btc_addr_bech32", "uuid_rfc4122", @@ -88,6 +88,7 @@ var ( "html_encoded", "url_encoded", "dir", + "dirpath", "jwt", "hostname_port", "timezone", @@ -104,6 +105,11 @@ var ( "semver", "dns_rfc1035_label", "credit_card", + "cve", + "luhn_checksum", + "mongodb", + "cron", + "spicedb", } ) @@ -121,7 +127,8 @@ func (ves validateErrors) Error() string { // ParseErr parses the content of validation error. func ParseErr(err error) string { - ves, ok := err.(validateErrors) + var ves validateErrors + ok := errors.As(err, &ves) if ok && len(ves) > 0 { return strings.Join(ves, ",") } @@ -172,7 +179,8 @@ func VerifyVarWithValue(field, other interface{}, tag string) error { func convertErr(err error) error { if err != nil { var ves validateErrors - if _, ok := err.(*validator.InvalidValidationError); ok { + var e *validator.InvalidValidationError + if errors.As(err, &e) { return ves } for _, err := range err.(validator.ValidationErrors) {