Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update go to 1.23 #397

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 64 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,93 @@
run:
timeout: 10m
# 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
- whitespace
disable-all: true

linters-settings:
gocritic:
disabled-checks:
- "ifElseChain"
- "assignOp"
- "appendAssign"
- "singleCaseSwitch"
- "exitAfterDefer" # FIXME
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.
importas:
no-unaliased: true
forbidigo:
forbid:
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
gosec:
excludes:
- G106 # Use of ssh InsecureIgnoreHostKey should be audited
- G115 # integer overflow conversion
- G204 # Audit use of command execution
- G402 # TLS MinVersion too low
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.18"
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/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

meta.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/ftpgrab/v7

go 1.21
go 1.23.0

require (
github.com/alecthomas/kong v1.6.0
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
2 changes: 1 addition & 1 deletion internal/journal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func (c *Client) Add(entry Entry) {

// IsEmpty checks if journal is empty
func (c *Client) IsEmpty() bool {
return c.Entries == nil || len(c.Entries) == 0
return len(c.Entries) == 0
}
2 changes: 1 addition & 1 deletion internal/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (j Journal) MarshalJSON() ([]byte, error) {

// IsEmpty checks if journal is empty
func (j Journal) IsEmpty() bool {
return j.Entries == nil || len(j.Entries) == 0
return len(j.Entries) == 0
}
2 changes: 1 addition & 1 deletion internal/notif/script/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (c *Client) Send(jnl journal.Journal) error {
return errors.Wrap(err, strings.TrimSpace(stderr.String()))
}

log.Debug().Msgf(strings.TrimSpace(stdout.String()))
log.Debug().Msg(strings.TrimSpace(stdout.String()))
return nil
}
20 changes: 13 additions & 7 deletions internal/notif/webhook/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"bytes"
"context"
"encoding/json"
"net/http"

Expand Down Expand Up @@ -34,10 +35,6 @@ func (c *Client) Name() string {

// Send creates and sends a webhook notification with journal entries
func (c *Client) Send(jnl journal.Journal) error {
hc := http.Client{
Timeout: *c.cfg.Timeout,
}

body, err := json.Marshal(struct {
Version string `json:"ftpgrab_version,omitempty"`
ServerIP string `json:"server_ip,omitempty"`
Expand All @@ -53,7 +50,11 @@ func (c *Client) Send(jnl journal.Journal) error {
return err
}

req, err := http.NewRequest(c.cfg.Method, c.cfg.Endpoint, bytes.NewBuffer(body))
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, c.cfg.Method, c.cfg.Endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}
Expand All @@ -66,6 +67,11 @@ func (c *Client) Send(jnl journal.Journal) error {

req.Header.Set("User-Agent", c.meta.UserAgent)

_, err = hc.Do(req)
return err
resp, err := hc.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

return nil
}
Loading