On Wed, May 2, 2018 at 5:18 PM, Tong Sun <suntong...@gmail.com> wrote: > > > On Wed, May 2, 2018 at 12:06 PM, Jan Mercl wrote: >> >> >> Ugly hack, completely wrong in the general case: >> https://play.golang.org/p/IM_lxT3PxmR > > > Oh, I now know why it was called "hack", because the thing would get > complicated and out of control very easily, e.g., > > {{add .v1 .v2}} > > So, still no solution. :-( > > How come the text Template library can deal with arbitrary data?
It deals with data using reflection. If you pass data as struct, then "$" is that struct, and $.Name, and ,Name refers to the field named Name in that struct If you pass data as a map[string]interface{}, then .Name refers to the value data["Name"] If all you need is to pass ENV, you can make it a function using Template.Funcs(), and call ENV to get env values. However, I think passing in a map is the easiest solution. > > -- > 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. -- 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.