Created
September 21, 2014 20:19
-
-
Save geraldstanje/2e6ca5b1ada087ec97c0 to your computer and use it in GitHub Desktop.
template fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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