Skip to content

Commit 0bc7034

Browse files
valid set by value custom_field.go
1 parent e0a3023 commit 0bc7034

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

field/custom_field.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@ func setBy(ctx context.Context, doc interface{}, fieldName string, ctxKey string
179179
fmt.Printf("ca type %v ", ca.Interface())
180180
switch a := ca.Interface().(type) {
181181
case string:
182-
by := ctx.Value(ctxKey)
183-
fmt.Printf("ctx value %v --> %v", ctxKey, by.(string))
184-
ca.SetString(by.(string))
182+
by := ctx.Value(ctxKey)
183+
fmt.Printf("ctx value %v --> %v", ctxKey, by.(string))
184+
if len(by.(string)) > 0 {
185+
ca.SetString(by.(string))
186+
}else {
187+
fmt.Printf("value with key %v is empty --> do not set", ctxKey, by)
188+
}
185189
default:
186190
fmt.Println("unsupported type to SetBy", a)
187191
}

0 commit comments

Comments
 (0)