Skip to content

Commit

Permalink
Merge pull request #1286 from crazy-max/go-1.23
Browse files Browse the repository at this point in the history
update to go 1.23
  • Loading branch information
crazy-max authored Dec 14, 2024
2 parents bdcb04e + 8fb9b97 commit 85facca
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 105 deletions.
80 changes: 67 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,100 @@ run:
- containers_image_openpgp
- exclude_graphdriver_btrfs
- exclude_graphdriver_devicemapper
# default uses Go version from the go.mod file, fallback on the env var
# `GOVERSION`, fallback on 1.17: https://golangci-lint.run/usage/configuration/#run-configuration
go: "1.23"

linters:
enable:
- bodyclose
- depguard
- forbidigo
- gocritic
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- importas
- ineffassign
- makezero
- misspell
- noctx
- nolintlint
- revive
- staticcheck
- testifylint
- typecheck
- errname
- makezero
- whitespace
- unused
- forbidigo
- whitespace
disable-all: true

linters-settings:
gocritic:
disabled-checks:
- "ifElseChain"
- "assignOp"
- "appendAssign"
- "singleCaseSwitch"
- "exitAfterDefer" # FIXME
importas:
alias:
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
alias: "ocispecs"
- pkg: "github.com/opencontainers/go-digest"
alias: "digest"
govet:
enable:
- nilness
- unusedwrite
depguard:
rules:
main:
deny:
# The io/ioutil package has been deprecated.
# https://go.dev/doc/go1.16#ioutil
- pkg: "io/ioutil"
desc: The io/ioutil package has been deprecated.
forbidigo:
forbid:
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
importas:
no-unaliased: true
- '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$'
gosec:
excludes:
- G204 # Audit use of command execution
- G402 # TLS MinVersion too low
- G115 # integer overflow conversion
config:
G306: "0644"
testifylint:
disable:
# disable rules that reduce the test condition
- "empty"
- "bool-compare"
- "len"
- "negative-positive"

issues:
exclude-files:
- ".*\\.pb\\.go$"
exclude-rules:
- linters:
- revive
text: "stutters"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "superfluous-else"
- linters:
- revive
text: "unused-parameter"
- linters:
- revive
text: "redefines-builtin-id"
- linters:
- revive
text: "if-return"

# show all
max-issues-per-linter: 0
max-same-issues: 0
# show all
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21"
ARG ALPINE_VERSION="3.19"
ARG GO_VERSION="1.23"
ARG ALPINE_VERSION="3.21"
ARG XX_VERSION="1.6.1"

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CliGlobals struct {

// BeforeApply is a hook that run cli cmd are executed.
func (s *CliGlobals) BeforeApply() (err error) {
s.conn, err = grpc.Dial(s.GRPCAuthority, grpc.WithTransportCredentials(insecure.NewCredentials()))
s.conn, err = grpc.NewClient(s.GRPCAuthority, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"time"
"unicode"

"github.com/AlecAivazis/survey/v2"
survey "github.com/AlecAivazis/survey/v2"
"github.com/crazy-max/diun/v4/pb"
"github.com/docker/go-units"
units "github.com/docker/go-units"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/tidwall/pretty"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -138,8 +138,8 @@ func (s *ImageRemoveCmd) Run(_ *Context) error {
// ImagePruneCmd holds image prune command
type ImagePruneCmd struct {
CliGlobals
//All bool `kong:"name='all',default='false',help='Remove all manifests from the database.'"`
//Filter string `kong:"name='filter',help='Provide filter values (e.g., until=24h).'"`
// All bool `kong:"name='all',default='false',help='Remove all manifests from the database.'"`
// Filter string `kong:"name='filter',help='Provide filter values (e.g., until=24h).'"`
Force bool `kong:"name='force',default='false',help='Do not prompt for confirmation.'"`
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
Author: "CrazyMax",
Version: version,
}
meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS))
meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)) //nolint:staticcheck // ignoring "SA1019: strings.Title is deprecated", as for our use we don't need full unicode support
if meta.Hostname, err = os.Hostname(); err != nil {
log.Fatal().Err(err).Msg("Cannot resolve hostname")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/crazy-max/diun/v4

go 1.21.0
go 1.23.0

require (
github.com/AlecAivazis/survey/v2 v2.3.7
Expand Down
2 changes: 1 addition & 1 deletion hack/gen.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21"
ARG GO_VERSION="1.23"
ARG PROTOC_VERSION="3.17.3"

# protoc is dynamically linked to glibc so can't use alpine base
Expand Down
6 changes: 3 additions & 3 deletions hack/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21"
ARG ALPINE_VERSION="3.18"
ARG GOLANGCI_LINT_VERSION="v1.55"
ARG GO_VERSION="1.23"
ARG ALPINE_VERSION="3.21"
ARG GOLANGCI_LINT_VERSION="v1.62"

FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
ENV GOFLAGS="-buildvcs=false"
Expand Down
4 changes: 2 additions & 2 deletions hack/vendor.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21"
ARG ALPINE_VERSION="3.18"
ARG GO_VERSION="1.23"
ARG ALPINE_VERSION="3.21"
ARG GOMOD_OUTDATED_VERSION="v0.8.0"

FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
},
},
RegOpts: model.RegOpts{
{
model.RegOpt{
Name: "myregistry",
Selector: model.RegOptSelectorName,
Username: "fii",
Password: "bor",
InsecureTLS: utl.NewFalse(),
Timeout: utl.NewDuration(5 * time.Second),
},
{
model.RegOpt{
Name: "docker.io",
Selector: model.RegOptSelectorImage,
Username: "foo",
Password: "bar",
InsecureTLS: utl.NewFalse(),
Timeout: utl.NewDuration(0),
},
{
model.RegOpt{
Name: "docker.io/crazymax",
Selector: model.RegOptSelectorImage,
UsernameFile: "./fixtures/run_secrets_username",
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestLoadEnv(t *testing.T) {
Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
RegOpts: model.RegOpts{
{
model.RegOpt{
Name: "docker.io",
Selector: model.RegOptSelectorImage,
UsernameFile: "./fixtures/run_secrets_username",
Expand Down
2 changes: 1 addition & 1 deletion internal/notif/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *Client) Send(entry model.NotifEntry) {
for _, n := range c.notifiers {
log.Debug().Str("image", entry.Image.String()).Msgf("Sending %s notification...", n.Name())
if err := n.Send(entry); err != nil {
log.Error().Err(err).Str("image", entry.Image.String()).Msgf("%s notification failed", strings.Title(n.Name()))
log.Error().Err(err).Str("image", entry.Image.String()).Msgf("%s notification failed", strings.Title(n.Name())) //nolint:staticcheck // ignoring "SA1019: strings.Title is deprecated", as for our use we don't need full unicode support
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions internal/notif/discord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discord

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -41,10 +42,6 @@ func (c *Client) Name() string {
func (c *Client) Send(entry model.NotifEntry) error {
var content bytes.Buffer

hc := http.Client{
Timeout: *c.cfg.Timeout,
}

message, err := msg.New(msg.Options{
Meta: c.meta,
Entry: entry,
Expand Down Expand Up @@ -125,7 +122,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err
}

req, err := http.NewRequest("POST", u.String(), dataBuf)
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
if err != nil {
return err
}
Expand All @@ -137,6 +138,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusNoContent {
return errors.Errorf("unexpected HTTP status %d: %s", resp.StatusCode, resp.Body)
Expand Down
12 changes: 7 additions & 5 deletions internal/notif/gotify/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gotify

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/url"
Expand Down Expand Up @@ -44,10 +45,6 @@ func (c *Client) Send(entry model.NotifEntry) error {
return errors.Wrap(err, "cannot retrieve token secret for Gotify notifier")
}

hc := http.Client{
Timeout: *c.cfg.Timeout,
}

message, err := msg.New(msg.Options{
Meta: c.meta,
Entry: entry,
Expand Down Expand Up @@ -92,7 +89,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
q.Set("token", token)
u.RawQuery = q.Encode()

req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(jsonBody))
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, "POST", u.String(), bytes.NewBuffer(jsonBody))
if err != nil {
return err
}
Expand All @@ -105,6 +106,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
var errBody struct {
Expand Down
12 changes: 7 additions & 5 deletions internal/notif/ntfy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ntfy

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -38,10 +39,6 @@ func (c *Client) Name() string {

// Send creates and sends a ntfy notification with an entry
func (c *Client) Send(entry model.NotifEntry) error {
hc := http.Client{
Timeout: *c.cfg.Timeout,
}

message, err := msg.New(msg.Options{
Meta: c.meta,
Entry: entry,
Expand Down Expand Up @@ -84,7 +81,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
q := u.Query()
u.RawQuery = q.Encode()

req, err := http.NewRequest("POST", u.String(), dataBuf)
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
if err != nil {
return err
}
Expand All @@ -99,6 +100,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
var errBody struct {
Expand Down
Loading

0 comments on commit 85facca

Please sign in to comment.