Skip to content

Commit 6da4beb

Browse files
authored
refactor: use std slices, maps package (#419)
1 parent 06d27b8 commit 6da4beb

File tree

9 files changed

+53
-57
lines changed

9 files changed

+53
-57
lines changed

commands/fetch-oracle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package commands
22

33
import (
44
"encoding/xml"
5+
"slices"
56
"strings"
67
"time"
78

89
"github.com/inconshreveable/log15"
910
"github.com/spf13/cobra"
1011
"github.com/spf13/viper"
11-
"golang.org/x/exp/slices"
1212
"golang.org/x/xerrors"
1313

1414
c "github.com/vulsio/goval-dictionary/config"

db/db.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,6 @@ func getAmazonLinuxVer(osVersion string) string {
130130
return "1"
131131
}
132132

133-
// IndexChunk has a starting point and an ending point for Chunk
134-
type IndexChunk struct {
135-
From, To int
136-
}
137-
138-
func chunkSlice(length int, chunkSize int) <-chan IndexChunk {
139-
ch := make(chan IndexChunk)
140-
141-
go func() {
142-
defer close(ch)
143-
144-
for i := 0; i < length; i += chunkSize {
145-
idx := IndexChunk{i, i + chunkSize}
146-
if length < idx.To {
147-
idx.To = length
148-
}
149-
ch <- idx
150-
}
151-
}()
152-
153-
return ch
154-
}
155-
156133
func filterByRedHatMajor(packs []models.Package, majorVer string) (filtered []models.Package) {
157134
for _, p := range packs {
158135
if p.NotFixedYet ||

db/rdb.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import (
77
"fmt"
88
"io"
99
"log"
10+
"maps"
1011
"os"
12+
"slices"
1113
"strings"
1214
"time"
1315

1416
"github.com/cheggaaa/pb/v3"
1517
"github.com/glebarez/sqlite"
1618
"github.com/inconshreveable/log15"
1719
"github.com/spf13/viper"
18-
"golang.org/x/exp/maps"
1920
"golang.org/x/xerrors"
2021
"gorm.io/driver/mysql"
2122
"gorm.io/driver/postgres"
@@ -237,7 +238,7 @@ func (r *RDBDriver) GetByPackName(family, osVer, packName, arch string) ([]model
237238
for _, d := range defs {
238239
m[d.DefinitionID] = d
239240
}
240-
return maps.Values(m), nil
241+
return slices.Collect(maps.Values(m)), nil
241242
default:
242243
return defs, nil
243244
}
@@ -292,7 +293,7 @@ func (r *RDBDriver) GetByCveID(family, osVer, cveID, arch string) ([]models.Defi
292293
for _, d := range defs {
293294
m[d.DefinitionID] = d
294295
}
295-
return maps.Values(m), nil
296+
return slices.Collect(maps.Values(m)), nil
296297
default:
297298
return defs, nil
298299
}
@@ -437,25 +438,25 @@ func (r *RDBDriver) InsertOval(root *models.Root) error {
437438
}
438439
return os.Stderr
439440
}())
440-
for idx := range chunkSlice(len(defs), 998) {
441+
for chunk := range slices.Chunk(defs, 998) {
441442
var advs []models.Advisory
442-
if err := tx.Model(defs[idx.From:idx.To]).Association("Advisory").Find(&advs); err != nil {
443+
if err := tx.Model(chunk).Association("Advisory").Find(&advs); err != nil {
443444
tx.Rollback()
444445
return xerrors.Errorf("Failed to delete: %w", err)
445446
}
446447

447-
for idx2 := range chunkSlice(len(advs), 998) {
448-
if err := tx.Select(clause.Associations).Unscoped().Delete(advs[idx2.From:idx2.To]).Error; err != nil {
448+
for chunk2 := range slices.Chunk(advs, 998) {
449+
if err := tx.Select(clause.Associations).Unscoped().Delete(chunk2).Error; err != nil {
449450
tx.Rollback()
450451
return xerrors.Errorf("Failed to delete: %w", err)
451452
}
452453
}
453454

454-
if err := tx.Select(clause.Associations).Unscoped().Delete(defs[idx.From:idx.To]).Error; err != nil {
455+
if err := tx.Select(clause.Associations).Unscoped().Delete(chunk).Error; err != nil {
455456
tx.Rollback()
456457
return xerrors.Errorf("Failed to delete: %w", err)
457458
}
458-
bar.Add(idx.To - idx.From)
459+
bar.Add(len(chunk))
459460
}
460461
if err := tx.Unscoped().Where("id = ?", old.ID).Delete(&models.Root{}).Error; err != nil {
461462
tx.Rollback()
@@ -480,25 +481,25 @@ func (r *RDBDriver) InsertOval(root *models.Root) error {
480481
root.Definitions[i].RootID = root.ID
481482
}
482483

483-
for idx := range chunkSlice(len(root.Definitions), batchSize) {
484-
if err := tx.Omit("AffectedPacks").Create(root.Definitions[idx.From:idx.To]).Error; err != nil {
484+
for chunk := range slices.Chunk(root.Definitions, batchSize) {
485+
if err := tx.Omit("AffectedPacks").Create(chunk).Error; err != nil {
485486
tx.Rollback()
486487
return xerrors.Errorf("Failed to insert Definitions. err: %w", err)
487488
}
488489

489-
for _, d := range root.Definitions[idx.From:idx.To] {
490-
for idx2 := range chunkSlice(len(d.AffectedPacks), batchSize) {
491-
for i := range d.AffectedPacks[idx2.From:idx2.To] {
492-
d.AffectedPacks[idx2.From+i].DefinitionID = d.ID
493-
}
494-
if err := tx.Create(d.AffectedPacks[idx2.From:idx2.To]).Error; err != nil {
490+
for _, d := range chunk {
491+
for i := range d.AffectedPacks {
492+
d.AffectedPacks[i].DefinitionID = d.ID
493+
}
494+
for chunk2 := range slices.Chunk(d.AffectedPacks, batchSize) {
495+
if err := tx.Create(chunk2).Error; err != nil {
495496
tx.Rollback()
496497
return xerrors.Errorf("Failed to insert AffectedPacks. err: %w", err)
497498
}
498499
}
499500
}
500501

501-
bar.Add(idx.To - idx.From)
502+
bar.Add(len(chunk))
502503
}
503504
bar.Finish()
504505

db/redis.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"maps"
910
"os"
11+
"slices"
1012
"strconv"
1113
"strings"
1214
"time"
@@ -15,7 +17,6 @@ import (
1517
"github.com/go-redis/redis/v8"
1618
"github.com/inconshreveable/log15"
1719
"github.com/spf13/viper"
18-
"golang.org/x/exp/maps"
1920
"golang.org/x/xerrors"
2021

2122
c "github.com/vulsio/goval-dictionary/config"
@@ -458,9 +459,9 @@ func (r *RedisDriver) InsertOval(root *models.Root) (err error) {
458459
}
459460
return os.Stderr
460461
}())
461-
for idx := range chunkSlice(len(root.Definitions), batchSize) {
462+
for chunk := range slices.Chunk(root.Definitions, batchSize) {
462463
pipe := r.conn.Pipeline()
463-
for _, def := range root.Definitions[idx.From:idx.To] {
464+
for _, def := range chunk {
464465
var dj []byte
465466
if dj, err = json.Marshal(def); err != nil {
466467
return xerrors.Errorf("Failed to marshal json. err: %w", err)
@@ -510,7 +511,7 @@ func (r *RedisDriver) InsertOval(root *models.Root) (err error) {
510511
if _, err = pipe.Exec(ctx); err != nil {
511512
return xerrors.Errorf("Failed to exec pipeline. err: %w", err)
512513
}
513-
bar.Add(idx.To - idx.From)
514+
bar.Add(len(chunk))
514515
}
515516
bar.Finish()
516517

@@ -521,10 +522,11 @@ func (r *RedisDriver) InsertOval(root *models.Root) (err error) {
521522
}
522523
return os.Stderr
523524
}())
524-
keys := maps.Keys(advs)
525-
for idx := range chunkSlice(len(keys), batchSize) {
525+
526+
keys := slices.Collect(maps.Keys(advs))
527+
for chunk := range slices.Chunk(keys, batchSize) {
526528
pipe := r.conn.Pipeline()
527-
for _, adv := range keys[idx.From:idx.To] {
529+
for _, adv := range chunk {
528530
var aj []byte
529531
if aj, err = json.Marshal(advs[adv]); err != nil {
530532
return xerrors.Errorf("Failed to marshal json. err: %w", err)
@@ -539,7 +541,7 @@ func (r *RedisDriver) InsertOval(root *models.Root) (err error) {
539541
if _, err = pipe.Exec(ctx); err != nil {
540542
return xerrors.Errorf("Failed to exec pipeline. err: %w", err)
541543
}
542-
bar.Add(idx.To - idx.From)
544+
bar.Add(len(chunk))
543545
}
544546
bar.Finish()
545547

fetcher/redhat/redhat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"bytes"
66
"fmt"
77
"io"
8+
"slices"
89
"strconv"
910
"strings"
1011

1112
"github.com/inconshreveable/log15"
12-
"golang.org/x/exp/slices"
1313
"golang.org/x/xerrors"
1414

1515
"github.com/vulsio/goval-dictionary/fetcher/util"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
github.com/spf13/cobra v1.8.1
1717
github.com/spf13/viper v1.19.0
1818
github.com/ulikunitz/xz v0.5.12
19-
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
2019
golang.org/x/net v0.29.0
2120
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
2221
gopkg.in/yaml.v2 v2.4.0
@@ -67,6 +66,7 @@ require (
6766
go.uber.org/atomic v1.9.0 // indirect
6867
go.uber.org/multierr v1.9.0 // indirect
6968
golang.org/x/crypto v0.27.0 // indirect
69+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
7070
golang.org/x/sync v0.8.0 // indirect
7171
golang.org/x/sys v0.25.0 // indirect
7272
golang.org/x/term v0.24.0 // indirect

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
88
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1010
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
11+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1112
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
1213
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
1314
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
1415
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
1516
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
1617
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
1718
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
19+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1820
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1921
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
2022
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
@@ -33,6 +35,7 @@ github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzq
3335
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3436
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3537
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
38+
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
3639
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
3740
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3841
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
@@ -62,7 +65,9 @@ github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3t
6265
github.com/knqyf263/go-rpm-version v0.0.0-20220614171824-631e686d1075 h1:aC6MEAs3PE3lWD7lqrJfDxHd6hcced9R4JTZu85cJwU=
6366
github.com/knqyf263/go-rpm-version v0.0.0-20220614171824-631e686d1075/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
6467
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
68+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
6569
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
70+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
6671
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
6772
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
6873
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
@@ -81,18 +86,23 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
8186
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
8287
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
8388
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
89+
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
8490
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
91+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
8592
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
93+
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
8694
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
8795
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
8896
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8997
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
98+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9099
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
91100
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
92101
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
93102
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
94103
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
95104
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
105+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
96106
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
97107
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
98108
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
@@ -155,9 +165,11 @@ golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3j
155165
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
156166
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
157167
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
168+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
158169
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
159170
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
160171
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
172+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
161173
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
162174
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
163175
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

models/redhat/redhat.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package redhat
22

33
import (
44
"fmt"
5+
"maps"
6+
"slices"
57
"strings"
68
"time"
79

810
version "github.com/knqyf263/go-rpm-version"
911
"github.com/spf13/viper"
10-
"golang.org/x/exp/maps"
1112

1213
"github.com/vulsio/goval-dictionary/models"
1314
"github.com/vulsio/goval-dictionary/models/util"
@@ -112,7 +113,7 @@ func ConvertToModel(v string, roots []Root) []models.Definition {
112113
}
113114
}
114115
}
115-
return maps.Values(defs)
116+
return slices.Collect(maps.Values(defs))
116117
}
117118

118119
func collectRedHatPacks(v string, cri Criteria) []models.Package {
@@ -145,7 +146,7 @@ func collectRedHatPacks(v string, cri Criteria) []models.Package {
145146

146147
pkgs[n] = p
147148
}
148-
return maps.Values(pkgs)
149+
return slices.Collect(maps.Values(pkgs))
149150
}
150151

151152
func walkRedHat(cri Criteria, acc []models.Package, label string) []models.Package {

util/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package util
22

3-
import "golang.org/x/exp/maps"
3+
import (
4+
"maps"
5+
"slices"
6+
)
47

58
// Unique return unique elements
69
func Unique[T comparable](s []T) []T {
710
m := map[T]struct{}{}
811
for _, v := range s {
912
m[v] = struct{}{}
1013
}
11-
return maps.Keys(m)
14+
return slices.Collect(maps.Keys(m))
1215
}

0 commit comments

Comments
 (0)