chore: fix panic when dumping OnIdentified

This commit is contained in:
andig 2023-12-05 10:28:30 +01:00
parent 9883baa8a6
commit 94760ac32b
2 changed files with 17 additions and 5 deletions

View file

@ -2,7 +2,6 @@ package api
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"github.com/fatih/structs" "github.com/fatih/structs"
@ -19,10 +18,9 @@ type ActionConfig struct {
// String implements Stringer and returns the ActionConfig as comma-separated key:value string // String implements Stringer and returns the ActionConfig as comma-separated key:value string
func (a ActionConfig) String() string { func (a ActionConfig) String() string {
var s []string var s []string
for k, v := range structs.Map(a) { for _, f := range structs.Fields(a) {
val := reflect.ValueOf(v) if !f.IsZero() {
if v != nil && !val.IsNil() { s = append(s, fmt.Sprintf("%s:%v", f.Name(), f.Value()))
s = append(s, fmt.Sprintf("%s:%v", k, val.Elem()))
} }
} }
return strings.Join(s, ", ") return strings.Join(s, ", ")

14
api/actionconfig_test.go Normal file
View file

@ -0,0 +1,14 @@
package api
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestActionConfigString(t *testing.T) {
var a ActionConfig
assert.NotPanics(t, func() {
_ = a.String()
})
}