1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 06:02:27 +08:00

refactor: make package variable defaultTagName unexported

This commit is contained in:
dudaodong
2023-03-15 15:08:56 +08:00
parent 534c7a0abc
commit f79693804b

View File

@@ -7,7 +7,7 @@ import (
)
// DefaultTagName is the default tag for struct fields to lookup.
var DefaultTagName = "json"
var defaultTagName = "json"
// Struct is abstract struct for provide several high level functions
type Struct struct {
@@ -18,15 +18,25 @@ type Struct struct {
}
// New returns a new *Struct
func New(value any) *Struct {
func New(value any, tagName ...string) *Struct {
value = pointer.ExtractPointer(value)
v := reflect.ValueOf(value)
t := reflect.TypeOf(value)
tn := defaultTagName
if len(tagName) > 0 {
tn = tagName[0]
}
// if need: can also set defaultTagName to tn across structutil package level
// defaultTagName = tn
return &Struct{
raw: value,
rtype: t,
rvalue: v,
TagName: DefaultTagName,
TagName: tn,
}
}