Skip to content

How to provide an in-memory data (map/struct) as the datasource/context when rendering a template with Gomplate APIs in Go? #2001

Answered by hairyhenderson
phong2tran asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the post @phong2tran, always nice to hear of projects where gomplate's being used!

I see you're looking at using the v3 gomplate module, which is fine - that's the latest major release. However, be aware that there's also a v4 module which may be slightly easier to use (I'm thinking of the Renderer in particular).

In particular, if you use the v4 module, you can provide NewRenderer with an FSProvider option, where you can supply an in-memory filesystem as provider. It's somewhat more awkward than simply using text/template directly though, where you can provide arbitrary structs or maps directly as the context. Speaking of which, if you just want to render templates programatic…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by phong2tran
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants