Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Created September 21, 2014 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldstanje/2e6ca5b1ada087ec97c0 to your computer and use it in GitHub Desktop.
Save geraldstanje/2e6ca5b1ada087ec97c0 to your computer and use it in GitHub Desktop.
template fun
package main
import (
"log"
"os"
"text/template"
"regexp"
)
var reg = regexp.MustCompile(`(^[^/]+[\w]+)\(([\w]*)[,\s]*([\w]*)\);`)
func main() {
// Define a template.
const input = `
start:
{{.OnLight}}
:end
`
myparam := `"some parameter"`
function := map[string]string{
"OnLight": `
blah(5664,` + myparam + `);
nyan(69,666);
//multiline makes it easier
`,
}
t := template.Must(template.New("code").Parse(input))
err := t.Execute(os.Stdout, function)
if err != nil {
log.Println("executing template:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment