fix notify args filtering

This commit is contained in:
c9s 2022-06-09 12:31:50 +08:00
parent e17535e651
commit fc0457cefe
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -51,7 +51,8 @@ func (m *Notifiability) AddNotifier(notifier Notifier) {
func (m *Notifiability) Notify(obj interface{}, args ...interface{}) {
if str, ok := obj.(string); ok {
logrus.Infof(str, args...)
simpleArgs := filterSimpleArgs(args)
logrus.Infof(str, simpleArgs...)
}
for _, n := range m.notifiers {
@ -64,3 +65,14 @@ func (m *Notifiability) NotifyTo(channel string, obj interface{}, args ...interf
n.NotifyTo(channel, obj, args...)
}
}
func filterSimpleArgs(args []interface{}) (simpleArgs []interface{}) {
for _, arg := range args {
switch arg.(type) {
case int, int64, int32, uint64, uint32, string, []byte, float64, float32:
simpleArgs = append(simpleArgs, arg)
}
}
return simpleArgs
}