chore: fix panic when dumping OnIdentified
This commit is contained in:
parent
9883baa8a6
commit
94760ac32b
2 changed files with 17 additions and 5 deletions
|
|
@ -2,7 +2,6 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
|
|
@ -19,10 +18,9 @@ type ActionConfig struct {
|
|||
// String implements Stringer and returns the ActionConfig as comma-separated key:value string
|
||||
func (a ActionConfig) String() string {
|
||||
var s []string
|
||||
for k, v := range structs.Map(a) {
|
||||
val := reflect.ValueOf(v)
|
||||
if v != nil && !val.IsNil() {
|
||||
s = append(s, fmt.Sprintf("%s:%v", k, val.Elem()))
|
||||
for _, f := range structs.Fields(a) {
|
||||
if !f.IsZero() {
|
||||
s = append(s, fmt.Sprintf("%s:%v", f.Name(), f.Value()))
|
||||
}
|
||||
}
|
||||
return strings.Join(s, ", ")
|
||||
|
|
|
|||
14
api/actionconfig_test.go
Normal file
14
api/actionconfig_test.go
Normal 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()
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue