From 8cd7f7a2d8b023d8842447c76205958377b12aca Mon Sep 17 00:00:00 2001 From: Name <1911860538@qq.com> Date: Sun, 22 Mar 2026 10:50:16 +0800 Subject: [PATCH] refactor(core): replace TakeOne usage with cmp.Or (#5461) Co-authored-by: 1911860538 --- core/mapping/utils.go | 6 +++--- core/stringx/strings.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/mapping/utils.go b/core/mapping/utils.go index 1c281e328..dc499b138 100644 --- a/core/mapping/utils.go +++ b/core/mapping/utils.go @@ -1,6 +1,7 @@ package mapping import ( + "cmp" "encoding/json" "errors" "fmt" @@ -12,7 +13,6 @@ import ( "sync" "github.com/zeromicro/go-zero/core/lang" - "github.com/zeromicro/go-zero/core/stringx" ) const ( @@ -278,7 +278,7 @@ func parseKeyAndOptions(tagName string, field reflect.StructField) (string, *fie cache, ok := optionsCache[value] cacheLock.RUnlock() if ok { - return stringx.TakeOne(cache.key, field.Name), cache.options, cache.err + return cmp.Or(cache.key, field.Name), cache.options, cache.err } key, options, err := doParseKeyAndOptions(field, value) @@ -290,7 +290,7 @@ func parseKeyAndOptions(tagName string, field reflect.StructField) (string, *fie } cacheLock.Unlock() - return stringx.TakeOne(key, field.Name), options, err + return cmp.Or(key, field.Name), options, err } // support below notations: diff --git a/core/stringx/strings.go b/core/stringx/strings.go index b6b8f5a82..5a9554a7b 100644 --- a/core/stringx/strings.go +++ b/core/stringx/strings.go @@ -141,6 +141,7 @@ func Substr(str string, start, stop int) (string, error) { } // TakeOne returns valid string if not empty or later one. +// Deprecated: use cmp.Or instead. func TakeOne(valid, or string) string { if len(valid) > 0 { return valid