Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/mapping/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mapping

import (
"cmp"
"encoding/json"
"errors"
"fmt"
Expand All @@ -12,7 +13,6 @@ import (
"sync"

"github.com/zeromicro/go-zero/core/lang"
"github.com/zeromicro/go-zero/core/stringx"
)

const (
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions core/stringx/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading