On Sat, 31 Dec 2016 07:45:27 -0800 (PST)
Joseph Lorenzini <jalo...@gmail.com> wrote:

> So I know why this can't work. :) My question is the following: if
> you have a type that you want to be private (e.g struct), how would
> you template that data? Use a different data structure? Use
> reflection?

Have your struct implement an interface; export that interface's type
and make all the exported functions of your package which return
instances of that private struct type return that interface instead.

Any template which is to render your values of that unexported type,
will be required to call methods on your values instead of accessing
the fields directly.  But that's the reasonable price to pay if you
don't want to expose your type for whatever reason.

This is a rather common "trick" in fact.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to