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

Nested object in map[string]interface{}. #25

Open
happyjian97 opened this issue Oct 31, 2022 · 1 comment
Open

Nested object in map[string]interface{}. #25

happyjian97 opened this issue Oct 31, 2022 · 1 comment

Comments

@happyjian97
Copy link

Is it possible to match a nested map object's key?
For example I having a variable shown below:

input := map[string]interface{}{
  "user": map[string]interface{}{
	  "name": "James",
	  "age":  "20",
  },
}

Example template

"Hi, my name is {{user.name}}, I'm {{user.age}} years old."

How do I get the {{user.name}} as the tags for template when calling ExecuteStringStd() ? I tried with {{user.name}} but it doesn't work.

@kiseeb
Copy link

kiseeb commented Aug 5, 2023

Alternativally :

var user = map[string]interface{}{
	  "name": "James",
	  "age":  "20",
  }

input := map[string]interface{}{
  "user.name": user[name],
  "user.age": user[age],
}

Thus you are protected from declaring a lot of maps or structs when templating a lot of records.

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

No branches or pull requests

2 participants