Thanks for this example!
I realized that to modify a variable I have to add a "var" function to 
return pointer of an object,  then I can use a "set" function to modify it.
And in the beginning I also provided "get" function to return the value 
referenced by the pointer, however later I suddenly found that I don't need 
to do that, go template will automatically return the object itself, rather 
than the pointer.
So this is my version https://play.golang.org/p/C1MtTKvdmGT
I think it is more concise and elegant than the original example :-)
Thanks so much for inspiring me!


On Thursday, October 10, 2013 at 7:52:20 PM UTC-7, Steven Blenkinsop wrote:
>
> You could do something like this if you had to:
> http://play.golang.org/p/SufZdsx-1v
>
>
> On Thu, Oct 10, 2013 at 8:18 AM, Accipiter Nisus <acci...@gmail.com 
> <javascript:>> wrote:
>
>>
>> Templates aren't the place for doing complex logic. Do it before you pass 
>>> the data to the template.
>>>
>> Whether or not assigning a new value to a variable is considered complex 
>> logic might be up for discussion.
>>
>> When the template package is used in a generic context (eg. Executing an 
>> arbitrary template file with an arbitrary json file), you might not have 
>> the luxury of doing precalculations.
>>
>> /ANisus
>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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