Original post

I am searching for ways to populate a Go template with sql values. So far I have 3 solutions that has pros and cons.

1. Sql standard library
Standard sql library is idiomatic, but you have to repeat the structs twice.

https://play.golang.org/p/lmrTCHbOwQW
http://94.237.92.101:5051/

2. Sqlx
Sqlx is an add on to standard library with “StructScan” which makes it more generic. I interpret this is a idiomatic way.

https://play.golang.org/p/abx0OQJmgyc
http://94.237.92.101:5052/

3. JSON experiment
This is DRY at the highest level, but I am considering it as a dead end. Because the function json_agg() does not work with joins etc. But I still consider it is an option for some cases.

https://play.golang.org/p/kmu1l75u2N4
http://94.237.92.101:5053/

My questions

  1. How do I get rid of the time garbage in 1 and 2? Is there a way to use time.Date(YYYY-MM-DD) in a struct sort of?
  2. Is there more ways to achieve this? Simpler or better?