update lint and dependency (#2)
All checks were successful
Go Action / goaction (push) Successful in 33s
All checks were successful
Go Action / goaction (push) Successful in 33s
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
26
.gitea/workflows/goaction.yml
Normal file
26
.gitea/workflows/goaction.yml
Normal file
@@ -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 ./...
|
||||||
|
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
linters-settings:
|
version: "2"
|
||||||
|
linters:
|
||||||
|
default: all
|
||||||
|
disable:
|
||||||
|
- wrapcheck
|
||||||
|
- wsl
|
||||||
|
- depguard
|
||||||
|
- revive
|
||||||
|
settings:
|
||||||
dupl:
|
dupl:
|
||||||
threshold: 100
|
threshold: 100
|
||||||
funlen:
|
funlen:
|
||||||
@@ -9,32 +17,39 @@ linters-settings:
|
|||||||
min-occurrences: 2
|
min-occurrences: 2
|
||||||
gocyclo:
|
gocyclo:
|
||||||
min-complexity: 15
|
min-complexity: 15
|
||||||
golint:
|
|
||||||
min-confidence: 0
|
|
||||||
govet:
|
|
||||||
check-shadowing: true
|
|
||||||
lll:
|
lll:
|
||||||
line-length: 140
|
line-length: 140
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
misspell:
|
misspell:
|
||||||
locale: US
|
locale: US
|
||||||
|
exclusions:
|
||||||
linters:
|
generated: lax
|
||||||
enable-all: true
|
presets:
|
||||||
disable:
|
- comments
|
||||||
- scopelint
|
- common-false-positives
|
||||||
- maligned
|
- legacy
|
||||||
- interfacer
|
- std-error-handling
|
||||||
- wrapcheck
|
rules:
|
||||||
|
- linters:
|
||||||
issues:
|
- mnd
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
path: _test\.go
|
||||||
exclude-rules:
|
- linters:
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- gomnd
|
|
||||||
- path: _suite\.go
|
|
||||||
linters:
|
|
||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
- gomnd
|
- mnd
|
||||||
|
path: _suite\.go
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
formatters:
|
||||||
|
enable:
|
||||||
|
- gci
|
||||||
|
- gofmt
|
||||||
|
- gofumpt
|
||||||
|
- goimports
|
||||||
|
- golines
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# encoding
|
# encoding
|
||||||
|
|
||||||
[](https://drone.gitoa.ru/go-4devs/encoding)
|

|
||||||
[](https://goreportcard.com/report/gitoa.ru/go-4devs/encoding)
|
[](https://goreportcard.com/report/gitoa.ru/go-4devs/encoding)
|
||||||
[](http://godoc.org/gitoa.ru/go-4devs/encoding)
|
[](http://godoc.org/gitoa.ru/go-4devs/encoding)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Encode writer from volume.
|
// 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.
|
// Decode reader to volume.
|
||||||
type Decode func(r io.Reader, v interface{}) error
|
type Decode func(r io.Reader, v any) error
|
||||||
|
|||||||
13
go.mod
13
go.mod
@@ -1,9 +1,14 @@
|
|||||||
module gitoa.ru/go-4devs/encoding
|
module gitoa.ru/go-4devs/encoding
|
||||||
|
|
||||||
go 1.16
|
go 1.22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v1.6.0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.11.1
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
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
|
||||||
)
|
)
|
||||||
|
|||||||
18
go.sum
18
go.sum
@@ -1,14 +1,12 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
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/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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ var (
|
|||||||
_ encoding.Encode = Encode
|
_ 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)
|
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)
|
return gob.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,18 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Unmarshal by gob decoder.
|
// Unmarshal by gob decoder.
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v any) error {
|
||||||
buf := bytes.NewBuffer(data)
|
buf := bytes.NewBuffer(data)
|
||||||
|
|
||||||
return gob.NewDecoder(buf).Decode(v)
|
return gob.NewDecoder(buf).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal by gob encoder.
|
// Marshal by gob encoder.
|
||||||
func Marshal(v interface{}) ([]byte, error) {
|
func Marshal(v any) ([]byte, error) {
|
||||||
var data bytes.Buffer
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ var (
|
|||||||
_ encoding.Encode = Encode
|
_ 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)
|
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)
|
return json.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import "unicode/utf8"
|
|||||||
//
|
//
|
||||||
// All values are true except for the ASCII control characters (0-31), the
|
// All values are true except for the ASCII control characters (0-31), the
|
||||||
// double quote ("), and the backslash character ("\").
|
// double quote ("), and the backslash character ("\").
|
||||||
|
//
|
||||||
|
//nolint:gochecknoglobals
|
||||||
var safeSet = [utf8.RuneSelf]bool{
|
var safeSet = [utf8.RuneSelf]bool{
|
||||||
' ': true,
|
' ': true,
|
||||||
'!': true,
|
'!': true,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"gitoa.ru/go-4devs/encoding"
|
"gitoa.ru/go-4devs/encoding"
|
||||||
)
|
)
|
||||||
@@ -31,25 +30,29 @@ func expected() Data {
|
|||||||
|
|
||||||
type DecodeSuite struct {
|
type DecodeSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
decode encoding.Decode
|
decode encoding.Decode
|
||||||
data io.Reader
|
data io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunSute run test by provider.
|
// RunDecode run test by provider.
|
||||||
func RunDecode(t *testing.T, decode encoding.Decode, data string) {
|
func RunDecode(t *testing.T, decode encoding.Decode, data string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
cs := DecodeSuite{
|
caseSuite := DecodeSuite{
|
||||||
decode: decode,
|
decode: decode,
|
||||||
data: bytes.NewBufferString(data),
|
data: bytes.NewBufferString(data),
|
||||||
|
Suite: suite.Suite{
|
||||||
|
Assertions: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.Run(t, &cs)
|
suite.Run(t, &caseSuite)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DecodeSuite) TestDecode() {
|
func (ds *DecodeSuite) TestDecode() {
|
||||||
var d Data
|
var d Data
|
||||||
|
|
||||||
require.Nil(ds.T(), ds.decode(ds.data, &d))
|
ds.Require().NoError(ds.decode(ds.data, &d))
|
||||||
require.Equal(ds.T(), expected(), d)
|
ds.Require().Equal(expected(), d)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Decode from reader to value.
|
// Decode from reader to value.
|
||||||
func Decode(r io.Reader, v interface{}) error {
|
func Decode(r io.Reader, v any) error {
|
||||||
_, err := toml.DecodeReader(r, v)
|
_, err := toml.NewDecoder(r).Decode(v)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode from value to writer.
|
// 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)
|
return toml.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
// Unmarshal bytes to inteface.
|
// Unmarshal bytes to inteface.
|
||||||
type Unmarshal func(data []byte, v interface{}) error
|
type Unmarshal func(data []byte, v any) error
|
||||||
|
|
||||||
// Marshal interface to bytes.
|
// Marshal interface to bytes.
|
||||||
type Marshal func(v interface{}) ([]byte, error)
|
type Marshal func(v any) ([]byte, error)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package json
|
//nolint:revive
|
||||||
|
package xml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
@@ -13,11 +14,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Decode from xml.
|
// 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)
|
return xml.NewDecoder(r).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode to xml.
|
// 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)
|
return xml.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Decode from reader to value.
|
// 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)
|
return yaml.NewDecoder(r).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode from value to writer.
|
// 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)
|
enc := yaml.NewEncoder(w)
|
||||||
defer enc.Close()
|
defer enc.Close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user