Skip to content

Commit

Permalink
feat: compatibility with Go 1.20
Browse files Browse the repository at this point in the history
Signed-off-by: juan131 <jariza@vmware.com>
  • Loading branch information
juan131 committed Nov 15, 2023
1 parent 4338f45 commit f915bb4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 13 additions & 1 deletion cmd/csaf_downloader/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ type forwarder struct {

// newForwarder creates a new forwarder.
func newForwarder(cfg *config) *forwarder {
queue := max(1, cfg.ForwardQueue)
queue := maxIntSlice(1, cfg.ForwardQueue)
return &forwarder{
cfg: cfg,
cmds: make(chan func(*forwarder), queue),
}
}

// maxIntSlice returns the maximum value of a slice of integers.
// TODO: replace with max built-in function in Go 1.21 (https://pkg.go.dev/builtin#max)
func maxIntSlice(v1 int, vn ...int) (m int) {
m = v1
for _, x := range vn {
if x > m {
m = x
}
}
return
}

// run runs the forwarder. Meant to be used in a Go routine.
func (f *forwarder) run() {
defer slog.Debug("forwarder done")
Expand Down
5 changes: 4 additions & 1 deletion examples/purls_searcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func newURLFinder(ids []string) *urlFinder {

// clear resets the url finder after a run on an advisory.
func (uf *urlFinder) clear() {
clear(uf.urls)
// TODO: replace with clear built-in function in Go 1.21 (https://pkg.go.dev/builtin#clear)
for i := range uf.urls {
uf.urls[i] = uf.urls[i][:0]
}
}

// dumpURLs dumps the found URLs to stdout.
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/csaf-poc/csaf_distribution/v3

go 1.21
go 1.20

require (
github.com/BurntSushi/toml v1.3.2
Expand Down

0 comments on commit f915bb4

Please sign in to comment.