Skip to content

Commit 397cb42

Browse files
1911860538kevwan
authored andcommitted
refactor(core): replace TakeOne usage with cmp.Or
1 parent db31013 commit 397cb42

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

core/mapping/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mapping
22

33
import (
4+
"cmp"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -12,7 +13,6 @@ import (
1213
"sync"
1314

1415
"github.com/zeromicro/go-zero/core/lang"
15-
"github.com/zeromicro/go-zero/core/stringx"
1616
)
1717

1818
const (
@@ -278,7 +278,7 @@ func parseKeyAndOptions(tagName string, field reflect.StructField) (string, *fie
278278
cache, ok := optionsCache[value]
279279
cacheLock.RUnlock()
280280
if ok {
281-
return stringx.TakeOne(cache.key, field.Name), cache.options, cache.err
281+
return cmp.Or(cache.key, field.Name), cache.options, cache.err
282282
}
283283

284284
key, options, err := doParseKeyAndOptions(field, value)
@@ -290,7 +290,7 @@ func parseKeyAndOptions(tagName string, field reflect.StructField) (string, *fie
290290
}
291291
cacheLock.Unlock()
292292

293-
return stringx.TakeOne(key, field.Name), options, err
293+
return cmp.Or(key, field.Name), options, err
294294
}
295295

296296
// support below notations:

core/stringx/strings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func Substr(str string, start, stop int) (string, error) {
141141
}
142142

143143
// TakeOne returns valid string if not empty or later one.
144+
// Deprecated: use cmp.Or instead.
144145
func TakeOne(valid, or string) string {
145146
if len(valid) > 0 {
146147
return valid

0 commit comments

Comments
 (0)