Home Execute template without a stuct of known format
Reply: 0

Execute template without a stuct of known format

user1048 Published in March 22, 2018, 9:16 pm

I have an app that is quite generic in nature.

Clients talk to it by sending json encoded messages that could contain any number of fields whose names the app does not care to know.

The app loads a configuration file and contains some template fields.

For example:

template = "Value read from json: {{.FilePath}}"


json from client = { "FilePath": "/tmp/filename.abc", "OtherField1":"value1" }


When using the normal golang template, a structure first needs to be defined for the json to be unmarshalled to. And then the template created and executed with values coming from the structure.

That's a problem, I don't want to have to hard code a structure together that ccontains the FilePath as a string an any other fields that a user might decide is useful. It makes it not generic.

How do I get around this? or is there perhaps another way to combining json and templates without using golang templates?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30911 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO