Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active June 7, 2017 07:59
Show Gist options
  • Save icholy/6342837 to your computer and use it in GitHub Desktop.
Save icholy/6342837 to your computer and use it in GitHub Desktop.
Go code generation: COG + Jinja2

Install deps

$ sudo pip install cogapp
$ sudo pip install jinja2

Run COG

$ cog.py -r main.go
Cogging main.go  (changed)
package main
import "fmt"
func main() {
/*[[[cog
import cog, jinja2
tmpl = '''
fmt.Println("{{ data.msg }}")
'''
data = { "msg": "Hello World" }
cog.out(jinja2.Template(tmpl).render(data=data))
]]]*/
fmt.Println("Hello World")
//[[[end]]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment