From 16f30007e7031423122375d87bfd94993f374cd6 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Thu, 30 May 2024 20:56:53 +0100 Subject: [PATCH] chore(aa): cosmetic. --- pkg/aa/pivot_root.go | 2 +- pkg/aa/template.go | 26 ++++++++++++-------------- pkg/logs/logs_test.go | 1 + 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/aa/pivot_root.go b/pkg/aa/pivot_root.go index 178b848d5..93847bf65 100644 --- a/pkg/aa/pivot_root.go +++ b/pkg/aa/pivot_root.go @@ -4,7 +4,7 @@ package aa -const PIVOTROOT = "pivot_root" +const PIVOTROOT Kind = "pivot_root" type PivotRoot struct { RuleBase diff --git a/pkg/aa/template.go b/pkg/aa/template.go index aed36f371..e20388cb6 100644 --- a/pkg/aa/template.go +++ b/pkg/aa/template.go @@ -7,7 +7,6 @@ package aa import ( "embed" "fmt" - "reflect" "strings" "text/template" ) @@ -176,12 +175,12 @@ func generateRequirementsWeights(requirements map[Kind]requirement) map[Kind]map } func join(i any) string { - switch reflect.TypeOf(i).Kind() { - case reflect.Slice: - return strings.Join(i.([]string), " ") - case reflect.Map: + switch i := i.(type) { + case []string: + return strings.Join(i, " ") + case map[string]string: res := []string{} - for k, v := range i.(map[string]string) { + for k, v := range i { res = append(res, k+"="+v) } return strings.Join(res, " ") @@ -191,16 +190,15 @@ func join(i any) string { } func cjoin(i any) string { - switch reflect.TypeOf(i).Kind() { - case reflect.Slice: - s := i.([]string) - if len(s) == 1 { - return s[0] + switch i := i.(type) { + case []string: + if len(i) == 1 { + return i[0] } - return "(" + strings.Join(s, " ") + ")" - case reflect.Map: + return "(" + strings.Join(i, " ") + ")" + case map[string]string: res := []string{} - for k, v := range i.(map[string]string) { + for k, v := range i { res = append(res, k+"="+v) } return "(" + strings.Join(res, " ") + ")" diff --git a/pkg/logs/logs_test.go b/pkg/logs/logs_test.go index 6332aa11e..ddf9c939b 100644 --- a/pkg/logs/logs_test.go +++ b/pkg/logs/logs_test.go @@ -6,6 +6,7 @@ package logs import ( "os" + "path/filepath" "reflect" "strings" "testing"