Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow a map[string]interface{} to be provided as the params also #32

Merged
merged 1 commit into from
Jun 15, 2024
Merged

allow a map[string]interface{} to be provided as the params also #32

merged 1 commit into from
Jun 15, 2024

Conversation

mzimmerman
Copy link
Contributor

In my use case I have a simple key/value list (not any hierarchy) and a map[string]interface{} is apparently natively supported, just was not exposed publicly -- this change exposes it publicly so that we don't have to create a dynamic struct at runtime using reflect and can instead just send the map

@bobiverse bobiverse self-assigned this Jun 15, 2024
@bobiverse bobiverse added the enhancement New feature or request label Jun 15, 2024
@bobiverse bobiverse merged commit 6ec8079 into bobiverse:master Jun 15, 2024
1 check passed
@@ -183,6 +183,8 @@ func (t *Template) fileToXMLStruct(fname string) *xmlNode {
func (t *Template) Params(v interface{}) {
// t.params = collectParams("", v)
switch val := v.(type) {
case map[string]interface{}:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did merged PR, but there was no issue (just no good comments).
There are some basic types, but complex types (like map) is sent through StructParams. Which now is confusing because there is similar func StructToParams.
StructParams will become AnyToParams to avoid confusion

	default:
		if reflect.ValueOf(v).Kind() == reflect.Struct {
			t.params = StructToParams(val)
		} else {
			// any other type try to convert
			t.params = AnyToParams(val)
		}
	}
	```

It will be changed in next release. See: `t.params_test.go`

@mzimmerman mzimmerman deleted the mapsasparams branch June 17, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants