Skip to content

Conversation

@ajg
Copy link
Owner

@ajg ajg commented Jul 18, 2017

No description provided.

@ajg ajg force-pushed the encode-to-with branch from 2ef78cf to 5f6a2d9 Compare July 18, 2017 04:48
@ajg ajg mentioned this pull request Jul 18, 2017
@godblesshugh
Copy link
Contributor

could import a global config for this? avoid to using a long and same params every time.

@ajg
Copy link
Owner Author

ajg commented Mar 18, 2019

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

@godblesshugh
Copy link
Contributor

godblesshugh commented Mar 18, 2019

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.

@ajg
Copy link
Owner Author

ajg commented Mar 18, 2019

@godblesshugh, 😆indeed. And yeah, a PR would be helpful.

@godblesshugh
Copy link
Contributor

#19

@buchanaf
Copy link

buchanaf commented Feb 4, 2020

@ajg, will this ever be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants