mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
refactor: make package variable defaultTagName unexported
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// DefaultTagName is the default tag for struct fields to lookup.
|
// 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
|
// Struct is abstract struct for provide several high level functions
|
||||||
type Struct struct {
|
type Struct struct {
|
||||||
@@ -18,15 +18,25 @@ type Struct struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new *Struct
|
// New returns a new *Struct
|
||||||
func New(value any) *Struct {
|
func New(value any, tagName ...string) *Struct {
|
||||||
value = pointer.ExtractPointer(value)
|
value = pointer.ExtractPointer(value)
|
||||||
v := reflect.ValueOf(value)
|
v := reflect.ValueOf(value)
|
||||||
t := reflect.TypeOf(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{
|
return &Struct{
|
||||||
raw: value,
|
raw: value,
|
||||||
rtype: t,
|
rtype: t,
|
||||||
rvalue: v,
|
rvalue: v,
|
||||||
TagName: DefaultTagName,
|
TagName: tn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user