Skip to content

Commit

Permalink
chore: update Go, CI, and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 31, 2023
1 parent 44d6724 commit f4895d1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 85 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,23 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.17
GOLANGCI_LINT_VERSION: v1.46.2
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.55.1
CGO_ENABLED: 0

steps:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version: ${{ env.GO_VERSION }}

- name: Check and get dependencies
run: |
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,19 @@ jobs:

strategy:
matrix:
go-version: [ 1.17, 1.18, 1.x ]
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
go-version: ${{ matrix.go-version }}

- name: Test
run: go test -v -cover ./...
Expand Down
33 changes: 21 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,34 @@ linters-settings:
- ^spew\.Print(f|ln)?$
- ^spew\.Dump$
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/pkg/errors
rules:
main:
deny:
- pkg: "github.com/instana/testify"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
godox:
keywords:
- FIXME

linters:
enable-all: true
disable:
- scopelint # Deprecated
- interfacer # Deprecated
- maligned # Deprecated
- golint # Deprecated
- exhaustivestruct # Deprecated
- sqlclosecheck # Not relevant (SQL)
- rowserrcheck # Not relevant (SQL)
- execinquery # Not relevant (SQL)
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- cyclop # duplicate of gocyclo
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- cyclop
- bodyclose
- prealloc
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/ldez/grignotin

go 1.17
go 1.20

require (
github.com/stretchr/testify v1.7.5
golang.org/x/mod v0.5.1
github.com/stretchr/testify v1.8.4
golang.org/x/mod v0.13.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
25 changes: 4 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
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/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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion goproxy/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error
return t.transport().RoundTrip(enrichedReq)
}

// Wrap Wrap a HTTP client Transport with the BasicAuthTransport.
// Wrap Wraps an HTTP client Transport with the BasicAuthTransport.
func (t *BasicAuthTransport) Wrap(client *http.Client) *http.Client {
backup := client.Transport
t.Transport = backup
Expand Down
12 changes: 8 additions & 4 deletions goproxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"

Expand All @@ -20,6 +19,8 @@ import (
const defaultProxyURL = "https://proxy.golang.org"

// VersionInfo is the representation of a version.
//
//nolint:musttag // data from Go proxy.
type VersionInfo struct {
Name string
Short string
Expand Down Expand Up @@ -62,7 +63,7 @@ func (c *Client) GetSources(moduleName, version string) ([]byte, error) {
return nil, handleError(resp)
}

raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
Expand Down Expand Up @@ -102,7 +103,7 @@ func (c *Client) GetModFile(moduleName, version string) (*modfile.File, error) {
return nil, handleError(resp)
}

all, err := ioutil.ReadAll(resp.Body)
all, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand All @@ -111,6 +112,7 @@ func (c *Client) GetModFile(moduleName, version string) (*modfile.File, error) {
}

// GetVersions gets all available module versions.
//
// <proxy URL>/<module name>/@v/list
func (c *Client) GetVersions(moduleName string) ([]string, error) {
uri := fmt.Sprintf("%s/%s/@v/list", c.proxyURL, mustEscapePath(moduleName))
Expand All @@ -137,12 +139,14 @@ func (c *Client) GetVersions(moduleName string) ([]string, error) {
}

// GetInfo gets information about a module version.
//
// <proxy URL>/<module name>/@v/<version>.info
func (c *Client) GetInfo(moduleName, version string) (*VersionInfo, error) {
return c.getInfo(fmt.Sprintf("%s/%s/@v/%s.info", c.proxyURL, mustEscapePath(moduleName), version))
}

// GetLatest gets information about the latest module version.
//
// <proxy URL>/<module name>/@latest
func (c *Client) GetLatest(moduleName string) (*VersionInfo, error) {
return c.getInfo(fmt.Sprintf("%s/%s/@latest", c.proxyURL, mustEscapePath(moduleName)))
Expand Down Expand Up @@ -179,7 +183,7 @@ func mustEscapePath(path string) string {
}

func handleError(resp *http.Response) error {
all, _ := ioutil.ReadAll(resp.Body)
all, _ := io.ReadAll(resp.Body)

return &APIError{
StatusCode: resp.StatusCode,
Expand Down
4 changes: 2 additions & 2 deletions goproxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package goproxy

import (
"fmt"
"io/ioutil"
"io"
"testing"
)

Expand All @@ -26,7 +26,7 @@ func TestClient_DownloadSources(t *testing.T) {
}
defer func() { _ = reader.Close() }()

raw, err := ioutil.ReadAll(reader)
raw, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion metago/metago.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Get(moduleName string) (*MetaGo, error) {
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("status code error: %d %s", resp.StatusCode, resp.Status)
}

Expand Down

0 comments on commit f4895d1

Please sign in to comment.