1
0
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:
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. // 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,
} }
} }