diff --git a/.gitea/workflows/goaction.yml b/.gitea/workflows/goaction.yml new file mode 100644 index 0000000..7f7abe9 --- /dev/null +++ b/.gitea/workflows/goaction.yml @@ -0,0 +1,26 @@ +name: Go Action + +on: [push, pull_request] + +jobs: + goaction: + runs-on: ubuntu-latest # Use a Gitea Actions runner label + steps: + - name: Check out repository code + uses: actions/checkout@v4 # Action to clone the repo + + - name: Set up Go + uses: actions/setup-go@v5 # Action to install a specific Go version + with: + go-version: '1.25.5' # Specify your required Go version + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v8 # Use the golangci-lint action + with: + version: v2.7.2 # Specify the linter version + # Optional: additional arguments + args: --verbose + + - name: Run go test + run: go test ./... + diff --git a/.golangci.yml b/.golangci.yml index 8935283..80271ec 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,12 @@ -linters-settings: +version: "2" +linters: + default: all + disable: + - wrapcheck + - wsl + - depguard + - revive + settings: dupl: threshold: 100 funlen: @@ -9,32 +17,39 @@ linters-settings: min-occurrences: 2 gocyclo: min-complexity: 15 - golint: - min-confidence: 0 - govet: - check-shadowing: true lll: line-length: 140 - maligned: - suggest-new: true misspell: - locale: US - -linters: - enable-all: true - disable: - - scopelint - - maligned - - interfacer - - wrapcheck - -issues: - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - - path: _test\.go - linters: - - gomnd - - path: _suite\.go - linters: - - exhaustivestruct - - gomnd + locale: US + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - mnd + path: _test\.go + - linters: + - exhaustivestruct + - mnd + path: _suite\.go + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + - golines + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/README.md b/README.md index aca7691..464d74e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # encoding -[![Build Status](https://drone.gitoa.ru/api/badges/go-4devs/encoding/status.svg)](https://drone.gitoa.ru/go-4devs/encoding) +![Build Status](https://gitoa.ru/go-4devs/encoding/actions/workflows/goaction.yml/badge.svg) [![Go Report Card](https://goreportcard.com/badge/gitoa.ru/go-4devs/encoding)](https://goreportcard.com/report/gitoa.ru/go-4devs/encoding) [![GoDoc](https://godoc.org/gitoa.ru/go-4devs/encoding?status.svg)](http://godoc.org/gitoa.ru/go-4devs/encoding) diff --git a/encoding.go b/encoding.go index d99d3ad..21253e0 100644 --- a/encoding.go +++ b/encoding.go @@ -5,7 +5,7 @@ import ( ) // Encode writer from volume. -type Encode func(w io.Writer, v interface{}) error +type Encode func(w io.Writer, v any) error // Decode reader to volume. -type Decode func(r io.Reader, v interface{}) error +type Decode func(r io.Reader, v any) error diff --git a/go.mod b/go.mod index ede6a3e..d9bf26c 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,14 @@ module gitoa.ru/go-4devs/encoding -go 1.16 +go 1.22 require ( - github.com/BurntSushi/toml v0.3.1 - github.com/stretchr/testify v1.7.0 - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b + github.com/BurntSushi/toml v1.6.0 + github.com/stretchr/testify v1.11.1 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect ) diff --git a/go.sum b/go.sum index f8ade2a..2d2505b 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,12 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= +github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -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/gob/encoding.go b/gob/encoding.go index ff6969d..9c9e5e3 100644 --- a/gob/encoding.go +++ b/gob/encoding.go @@ -12,10 +12,10 @@ var ( _ encoding.Encode = Encode ) -func Decode(r io.Reader, v interface{}) error { +func Decode(r io.Reader, v any) error { return gob.NewDecoder(r).Decode(v) } -func Encode(w io.Writer, v interface{}) error { +func Encode(w io.Writer, v any) error { return gob.NewEncoder(w).Encode(v) } diff --git a/gob/unmarshal.go b/gob/unmarshal.go index 90946a0..0293a65 100644 --- a/gob/unmarshal.go +++ b/gob/unmarshal.go @@ -13,16 +13,18 @@ var ( ) // Unmarshal by gob decoder. -func Unmarshal(data []byte, v interface{}) error { +func Unmarshal(data []byte, v any) error { buf := bytes.NewBuffer(data) return gob.NewDecoder(buf).Decode(v) } // Marshal by gob encoder. -func Marshal(v interface{}) ([]byte, error) { +func Marshal(v any) ([]byte, error) { var data bytes.Buffer - if err := gob.NewEncoder(&data).Encode(v); err != nil { + + err := gob.NewEncoder(&data).Encode(v) + if err != nil { return nil, err } diff --git a/json/encoding.go b/json/encoding.go index 722be61..8fde857 100644 --- a/json/encoding.go +++ b/json/encoding.go @@ -12,10 +12,10 @@ var ( _ encoding.Encode = Encode ) -func Decode(r io.Reader, v interface{}) error { +func Decode(r io.Reader, v any) error { return json.NewDecoder(r).Decode(v) } -func Encode(w io.Writer, v interface{}) error { +func Encode(w io.Writer, v any) error { return json.NewEncoder(w).Encode(v) } diff --git a/json/safe_set.go b/json/safe_set.go index a256d46..6a6a590 100644 --- a/json/safe_set.go +++ b/json/safe_set.go @@ -10,6 +10,8 @@ import "unicode/utf8" // // All values are true except for the ASCII control characters (0-31), the // double quote ("), and the backslash character ("\"). +// +//nolint:gochecknoglobals var safeSet = [utf8.RuneSelf]bool{ ' ': true, '!': true, diff --git a/test/decode_suite.go b/test/decode_suite.go index 7bfc01e..bd79a7e 100644 --- a/test/decode_suite.go +++ b/test/decode_suite.go @@ -6,7 +6,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "gitoa.ru/go-4devs/encoding" ) @@ -31,25 +30,29 @@ func expected() Data { type DecodeSuite struct { suite.Suite + decode encoding.Decode data io.Reader } -// RunSute run test by provider. +// RunDecode run test by provider. func RunDecode(t *testing.T, decode encoding.Decode, data string) { t.Helper() - cs := DecodeSuite{ + caseSuite := DecodeSuite{ decode: decode, data: bytes.NewBufferString(data), + Suite: suite.Suite{ + Assertions: nil, + }, } - suite.Run(t, &cs) + suite.Run(t, &caseSuite) } func (ds *DecodeSuite) TestDecode() { var d Data - require.Nil(ds.T(), ds.decode(ds.data, &d)) - require.Equal(ds.T(), expected(), d) + ds.Require().NoError(ds.decode(ds.data, &d)) + ds.Require().Equal(expected(), d) } diff --git a/toml/encoding.go b/toml/encoding.go index 2259c0d..fc30beb 100644 --- a/toml/encoding.go +++ b/toml/encoding.go @@ -13,13 +13,13 @@ var ( ) // Decode from reader to value. -func Decode(r io.Reader, v interface{}) error { - _, err := toml.DecodeReader(r, v) +func Decode(r io.Reader, v any) error { + _, err := toml.NewDecoder(r).Decode(v) return err } // Encode from value to writer. -func Encode(w io.Writer, v interface{}) error { +func Encode(w io.Writer, v any) error { return toml.NewEncoder(w).Encode(v) } diff --git a/unmarshal.go b/unmarshal.go index 5eda83c..1fe24cf 100644 --- a/unmarshal.go +++ b/unmarshal.go @@ -1,7 +1,7 @@ package encoding // Unmarshal bytes to inteface. -type Unmarshal func(data []byte, v interface{}) error +type Unmarshal func(data []byte, v any) error // Marshal interface to bytes. -type Marshal func(v interface{}) ([]byte, error) +type Marshal func(v any) ([]byte, error) diff --git a/xml/encoding.go b/xml/encoding.go index bbdff5e..29bcb13 100644 --- a/xml/encoding.go +++ b/xml/encoding.go @@ -1,4 +1,5 @@ -package json +//nolint:revive +package xml import ( "encoding/xml" @@ -13,11 +14,11 @@ var ( ) // Decode from xml. -func Decode(r io.Reader, v interface{}) error { +func Decode(r io.Reader, v any) error { return xml.NewDecoder(r).Decode(v) } // Encode to xml. -func Encode(w io.Writer, v interface{}) error { +func Encode(w io.Writer, v any) error { return xml.NewEncoder(w).Encode(v) } diff --git a/yaml/encoding.go b/yaml/encoding.go index d184f75..61aed58 100644 --- a/yaml/encoding.go +++ b/yaml/encoding.go @@ -13,12 +13,12 @@ var ( ) // Decode from reader to value. -func Decode(r io.Reader, v interface{}) error { +func Decode(r io.Reader, v any) error { return yaml.NewDecoder(r).Decode(v) } // Encode from value to writer. -func Encode(w io.Writer, v interface{}) error { +func Encode(w io.Writer, v any) error { enc := yaml.NewEncoder(w) defer enc.Close()