Skip to content

Commit 29875be

Browse files
authored
Merge pull request #4166 from saschagrunert/modernize
Modernize golang
2 parents f904e51 + c19d9bd commit 29875be

File tree

20 files changed

+68
-95
lines changed

20 files changed

+68
-95
lines changed

cmd/ci-reporter/cmd/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func GetGithubReportData(ctx context.Context, cfg Config, denyListFieldFilter, a
220220
// lookup project board information
221221
var queryCiSignalProjectBoard ciSignalProjectBoardGraphQLQuery
222222

223-
variablesProjectBoardFields := map[string]interface{}{
223+
variablesProjectBoardFields := map[string]any{
224224
"projectBoardID": githubv4.ID(ciSignalProjectBoardID),
225225
}
226226
if err := cfg.GithubClient.Query(ctx, &queryCiSignalProjectBoard, variablesProjectBoardFields); err != nil {

cmd/krel/cmd/release_notes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
13121312
}
13131313

13141314
// Check two values and print a prefix if they are different.
1315-
func pointIfChanged(label string, var1, var2 interface{}) string {
1315+
func pointIfChanged(label string, var1, var2 any) string {
13161316
changed := false
13171317
// Check if alues are string
13181318
var1String, ok1 := var1.(string)

cmd/krel/cmd/sign_blobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func runSignBlobs(signOpts *signOptions, signBlobOpts *signBlobOptions, args []s
169169

170170
gcsClient := object.NewGCS()
171171

172-
for _, file := range strings.Fields(output) {
172+
for file := range strings.FieldsSeq(output) {
173173
if strings.HasSuffix(file, ".sha256") || strings.HasSuffix(file, ".sha512") ||
174174
strings.HasSuffix(file, ":") || strings.HasSuffix(file, ".docker_tag") ||
175175
strings.Contains(file, "SHA256SUMS") || strings.Contains(file, "SHA512SUMS") ||

cmd/krel/cmd/testgrid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func runTestGridShot(opts *TestGridOptions) error {
121121
return fmt.Errorf("unable to retrieve release announcement form url: %s: %w", testGridDashboard, err)
122122
}
123123

124-
var result map[string]interface{}
124+
var result map[string]any
125125

126126
err = json.Unmarshal(content, &result)
127127
if err != nil {

cmd/publish-release/cmd/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ func getAssetsFromStrings(assetStrings []string) ([]sbom.Asset, error) {
192192
for _, s := range assetStrings {
193193
isBucket = false
194194

195-
if strings.HasPrefix(s, "gs:") {
196-
s = strings.TrimPrefix(s, "gs:")
195+
if after, ok := strings.CutPrefix(s, "gs:"); ok {
196+
s = after
197197
isBucket = true
198198
}
199199

cmd/release-notes/check.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24+
"slices"
2425

2526
"github.com/spf13/cobra"
2627

@@ -53,12 +54,8 @@ func (o *checkPROptions) ValidateAndFinish() error {
5354
lenErr = errors.New("no pull requests numbers specified")
5455
}
5556

56-
for _, n := range o.PullRequests {
57-
if n == 0 {
58-
prNrErr = errors.New("invalid pull request number (must be an integer larger than 0)")
59-
60-
break
61-
}
57+
if slices.Contains(o.PullRequests, 0) {
58+
prNrErr = errors.New("invalid pull request number (must be an integer larger than 0)")
6259
}
6360

6461
if o.GithubOrg == "" {

cmd/schedule-builder/cmd/markdown.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"embed"
2222
"fmt"
2323
"os"
24+
"slices"
2425
"strings"
2526
"text/template" // NOLINT // Mark text/template as not to be checked for producing yaml.
2627
"time"
@@ -156,7 +157,7 @@ func removeDotfromVersion(a string) string {
156157

157158
// process applies the data structure 'vars' onto an already
158159
// parsed template 't', and returns the resulting string.
159-
func process(t *template.Template, vars interface{}) string {
160+
func process(t *template.Template, vars any) string {
160161
var tmplBytes bytes.Buffer
161162

162163
err := t.Execute(&tmplBytes, vars)
@@ -167,7 +168,7 @@ func process(t *template.Template, vars interface{}) string {
167168
return tmplBytes.String()
168169
}
169170

170-
func processFile(fileName string, vars interface{}) string {
171+
func processFile(fileName string, vars any) string {
171172
tmpl, err := template.ParseFS(tpls, fileName)
172173
if err != nil {
173174
panic(err)
@@ -306,12 +307,8 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, eolBranches
306307
for i, sched := range schedule.Schedules {
307308
appendItem := true
308309

309-
for _, k := range removeSchedules {
310-
if i == k {
311-
appendItem = false
312-
313-
break
314-
}
310+
if slices.Contains(removeSchedules, i) {
311+
appendItem = false
315312
}
316313

317314
if appendItem {

pkg/changelog/impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type impl interface {
8383
) error
8484
ParseHTMLTemplate(text string) (*template.Template, error)
8585
TemplateExecute(
86-
tpl *template.Template, wr io.Writer, data interface{},
86+
tpl *template.Template, wr io.Writer, data any,
8787
) error
8888
Abs(path string) (string, error)
8989

@@ -198,7 +198,7 @@ func (*defaultImpl) ParseHTMLTemplate(text string) (*template.Template, error) {
198198
}
199199

200200
func (*defaultImpl) TemplateExecute(
201-
tpl *template.Template, wr io.Writer, data interface{},
201+
tpl *template.Template, wr io.Writer, data any,
202202
) error {
203203
return tpl.Execute(wr, data)
204204
}

pkg/consts/main.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ limitations under the License.
1616

1717
package consts
1818

19-
import "github.com/sirupsen/logrus"
19+
import (
20+
"slices"
21+
22+
"github.com/sirupsen/logrus"
23+
)
2024

2125
const (
2226
PackageCRITools string = "cri-tools"
@@ -72,15 +76,7 @@ func IsSupported(field string, input, expected []string) bool {
7276
notSupported := []string{}
7377

7478
for _, i := range input {
75-
supported := false
76-
77-
for _, j := range expected {
78-
if i == j {
79-
supported = true
80-
81-
break
82-
}
83-
}
79+
supported := slices.Contains(expected, i)
8480

8581
if !supported {
8682
notSupported = append(notSupported, i)

pkg/cve/cve.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,36 @@ type CVE struct {
3939

4040
// ReadRawInterface populates the CVE data struct from the raw array
4141
// as returned by the YAML parser.
42-
func (cve *CVE) ReadRawInterface(cvedata interface{}) error {
43-
if val, ok := cvedata.(map[interface{}]interface{})["id"].(string); ok {
42+
func (cve *CVE) ReadRawInterface(cvedata any) error {
43+
if val, ok := cvedata.(map[any]any)["id"].(string); ok {
4444
cve.ID = val
4545
}
4646

47-
if val, ok := cvedata.(map[interface{}]interface{})["title"].(string); ok {
47+
if val, ok := cvedata.(map[any]any)["title"].(string); ok {
4848
cve.Title = val
4949
}
5050

51-
if val, ok := cvedata.(map[interface{}]interface{})["issue"].(string); ok {
51+
if val, ok := cvedata.(map[any]any)["issue"].(string); ok {
5252
cve.TrackingIssue = val
5353
}
5454

55-
if val, ok := cvedata.(map[interface{}]interface{})["vector"].(string); ok {
55+
if val, ok := cvedata.(map[any]any)["vector"].(string); ok {
5656
cve.CVSSVector = val
5757
}
5858

59-
if val, ok := cvedata.(map[interface{}]interface{})["score"].(float64); ok {
59+
if val, ok := cvedata.(map[any]any)["score"].(float64); ok {
6060
cve.CVSSScore = float32(val)
6161
}
6262

63-
if val, ok := cvedata.(map[interface{}]interface{})["rating"].(string); ok {
63+
if val, ok := cvedata.(map[any]any)["rating"].(string); ok {
6464
cve.CVSSRating = val
6565
}
6666

67-
if val, ok := cvedata.(map[interface{}]interface{})["description"].(string); ok {
67+
if val, ok := cvedata.(map[any]any)["description"].(string); ok {
6868
cve.Description = val
6969
}
7070
// Linked PRs is a list of the PR IDs
71-
if val, ok := cvedata.(map[interface{}]interface{})["linkedPRs"].([]interface{}); ok {
71+
if val, ok := cvedata.(map[any]any)["linkedPRs"].([]any); ok {
7272
cve.LinkedPRs = []int{}
7373

7474
for _, prid := range val {

0 commit comments

Comments
 (0)