Skip to content

Commit 48f7206

Browse files
authored
refactor: set go 1.21 as minimal supported version (#104)
- [x] Upgrade go mod to 1.21 - [x] Remove go 1.20 from CI - [x] use `errors.Join` when necessary - [x] use builtin `max` when necessary --------- Signed-off-by: Eliott Bouhana <[email protected]>
1 parent 266e3a0 commit 48f7206

File tree

8 files changed

+14
-42
lines changed

8 files changed

+14
-42
lines changed

.github/workflows/_test_bare_metal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: false
99
matrix:
1010
runs-on: [ macos-14, macos-13, macos-12, ubuntu-22.04, ubuntu-20.04, windows-latest, arm-4core-linux ]
11-
go-version: [ '1.22', '1.21', '1.20' ]
11+
go-version: [ '1.22', '1.21' ]
1212
include:
1313
# Test with DD_APPSEC_WAF_LOG_LEVEL (only latest go version)
1414
- go-version: '1.22'

.github/workflows/_test_containerized.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- golang:{0}-buster
1717
# RPM-based image
1818
- amazonlinux:2 # pretty popular on AWS workloads
19-
go-version: [ "1.23-rc", "1.22", "1.21", "1.20" ]
19+
go-version: [ "1.23-rc", "1.22", "1.21" ]
2020
include:
2121
# Test with DD_APPSEC_WAF_LOG_LEVEL (only latest go, without any particular tag)
2222
- go-version: '1.23-rc'
@@ -34,8 +34,6 @@ jobs:
3434
# The amazonlinux:2 variant is only relevant for the default go version yum ships (currently 1.22)
3535
- go-version: '1.21'
3636
image: amazonlinux:2
37-
- go-version: '1.20'
38-
image: amazonlinux:2
3937
name: ${{ matrix.arch }} ${{ format(matrix.image, matrix.go-version) }} go${{ matrix.go-version }}${{ matrix.waf-log-level && format(' (DD_APPSEC_WAF_LOG_LEVEL={0})', matrix.waf-log-level) || '' }}
4038
# We use ARM runners when needed to avoid the performance hit of QEMU
4139
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'arm-4core-linux' }}

.github/workflows/ci.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ GOVERSION="$(go env GOVERSION)"
77
GOOS="$(go env GOOS)"
88
GOARCH="$(go env GOARCH)"
99

10-
case $GOVERSION in
11-
*1.20* ) CGOCHECK="GODEBUG=cgocheck=2";;
12-
*) CGOCHECK="GOEXPERIMENT=cgocheck2";;
13-
esac
14-
1510
contains() {
1611
case $1 in
1712
*$2*) echo true;;
@@ -47,7 +42,7 @@ run() {
4742

4843
if [ "$cgo" = "1" ]; then
4944
echo "Running again with cgocheck enabled..."
50-
env "$CGOCHECK" CGO_ENABLED=1 go test -shuffle=on -tags="$tags" -args -waf-build-tags="$test_tags" -waf-supported="$waf_enabled" ./...
45+
env "GOEXPERIMENT=cgocheck2" CGO_ENABLED=1 go test -shuffle=on -tags="$tags" -args -waf-build-tags="$test_tags" -waf-supported="$waf_enabled" ./...
5146
fi
5247

5348
# TODO: remove condition once we have native arm64 linux runners

encoder.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,6 @@ func depthOf(ctx context.Context, obj reflect.Value) (depth int, err error) {
446446

447447
obj, kind := resolvePointer(obj)
448448

449-
//TODO: Remove this once Go 1.21 is the minimum supported version (it adds `builtin.max`)
450-
max := func(x, y int) int {
451-
if x > y {
452-
return x
453-
}
454-
return y
455-
}
456-
457449
var itemDepth int
458450
switch kind {
459451
case reflect.Array, reflect.Slice:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/DataDog/go-libddwaf/v3
22

3-
go 1.20
3+
go 1.21
44

55
require (
66
github.com/ebitengine/purego v0.6.0-alpha.5

internal/bindings/waf_dl.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package bindings
99

1010
import (
11+
"errors"
1112
"fmt"
1213
"os"
1314

@@ -43,20 +44,13 @@ type wafSymbols struct {
4344
// The caller is responsible for calling wafDl.Close on the returned object once they
4445
// are done with it so that associated resources can be released.
4546
func NewWafDl() (dl *WafDl, err error) {
46-
var file string
47-
file, err = lib.DumpEmbeddedWAF()
47+
file, err := lib.DumpEmbeddedWAF()
4848
if err != nil {
4949
return
5050
}
5151
defer func() {
52-
rmErr := os.Remove(file)
53-
if rmErr != nil {
54-
if err == nil {
55-
err = rmErr
56-
} else {
57-
// TODO: rely on errors.Join() once go1.20 is our min supported Go version
58-
err = fmt.Errorf("%w; along with an error while removing %s: %v", err, file, rmErr)
59-
}
52+
if rmErr := os.Remove(file); rmErr != nil {
53+
err = errors.Join(err, fmt.Errorf("error removing %s: %w", file, rmErr))
6054
}
6155
}()
6256

@@ -68,8 +62,7 @@ func NewWafDl() (dl *WafDl, err error) {
6862
var symbols wafSymbols
6963
if symbols, err = resolveWafSymbols(handle); err != nil {
7064
if closeErr := purego.Dlclose(handle); closeErr != nil {
71-
// TODO: rely on errors.Join() once go1.20 is our min supported Go version
72-
err = fmt.Errorf("%w; along with an error while releasing the shared libddwaf library: %v", err, closeErr)
65+
err = errors.Join(err, fmt.Errorf("error released the shared libddwaf library: %w", closeErr))
7366
}
7467
return
7568
}
@@ -83,8 +76,7 @@ func NewWafDl() (dl *WafDl, err error) {
8376
})
8477
if err != nil {
8578
if closeErr := purego.Dlclose(handle); closeErr != nil {
86-
// TODO: rely on errors.Join() once go1.20 is our min supported Go version
87-
err = fmt.Errorf("%w; along with an error while releasing the shared libddwaf library: %v", err, closeErr)
79+
err = errors.Join(err, fmt.Errorf("error released the shared libddwaf library: %w", closeErr))
8880
}
8981
return
9082
}

internal/lib/lib.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package lib
1010
import (
1111
"bytes"
1212
"compress/gzip"
13+
"errors"
1314
"fmt"
1415
"io"
1516
"os"
@@ -29,17 +30,11 @@ func DumpEmbeddedWAF() (path string, err error) {
2930

3031
defer func() {
3132
if closeErr := file.Close(); closeErr != nil {
32-
if err != nil {
33-
// TODO: rely on errors.Join() once go1.20 is our min supported Go version
34-
err = fmt.Errorf("%w; along with an error while releasingclosing the temporary file: %v", err, closeErr)
35-
} else {
36-
err = fmt.Errorf("error closing file: %w", closeErr)
37-
}
33+
err = errors.Join(err, fmt.Errorf("error closing file: %w", closeErr))
3834
}
3935
if path != "" && err != nil {
4036
if rmErr := os.Remove(path); rmErr != nil {
41-
// TODO: rely on errors.Join() once go1.20 is our min supported Go version
42-
err = fmt.Errorf("%w; along with an error while releasingclosing the temporary file: %v", err, rmErr)
37+
err = errors.Join(err, fmt.Errorf("error removing file: %w", rmErr))
4338
}
4439
}
4540
}()

waf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Diagnostics struct {
3333
Version string
3434
}
3535

36-
// TopLevelErrors returns the list of top-level errors reported by the WAF on any of the Diagnostics
36+
// TopLevelError returns the list of top-level errors reported by the WAF on any of the Diagnostics
3737
// entries, rolled up into a single error value. Returns nil if no top-level errors were reported.
3838
// Individual, item-level errors might still exist.
3939
func (d *Diagnostics) TopLevelError() error {

0 commit comments

Comments
 (0)