Add EncodeToStringWith and EncodeToValuesWith convenience functions
could import a global config for this? avoid to using a long and same params every time.
could import a global config for this? avoid to using a long and same params every time.
@godblesshugh, great suggestion, and I wish I could have gotten to it earlier; alas, hopefully you can still take advantage of it. How about something like this: https://github.com/ajg/form/compare/options?expand=1
been 2 years πππ a little memory lost, but i found this in the repository i forked:
func EncodeToString(dst interface{}, needEmptyValue ...bool) (string, error) {
v := reflect.ValueOf(dst)
z := false
if len(needEmptyValue) != 0 {
z = needEmptyValue[0]
}
n, err := encodeToNode(v, z)
and this:
func fieldInfo(f reflect.StructField, tagName ...string) (k string, oe bool) {
_tagName := "form"
if len(tagName) > 0 {
_tagName = tagName[0]
}
if f.PkgPath != "" { // Skip private fields.
return omittedKey, oe
}
k = f.Name
tag := f.Tag.Get(_tagName)
if tag == "" {
if len(tagName) == 0 && _tagName != "json" {
return fieldInfo(f, "json") // using json as secondary
} else {
return k, oe
}
}
ps := strings.SplitN(tag, ",", 2)
if ps[0] != "" {
k = ps[0]
}
if len(ps) == 2 {
oe = ps[1] == "omitempty"
}
return k, oe
}
I can create a PR if it helps.
@godblesshugh, πindeed. And yeah, a PR would be helpful.
#19
@ajg, will this ever be merged?