Created
September 17, 2016 02:39
-
-
Save asit-dhal/8f3283b147f38ed69bbd56f88bcd154b to your computer and use it in GitHub Desktop.
define action demo golang template
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 ( | |
"fmt" | |
"html/template" | |
"os" | |
) | |
var defineDemo = ` | |
{{ define "a" }} Template A {{ end }} | |
{{define "b"}} Template B {{end}} | |
` | |
func main() { | |
var err error | |
t := template.New("defineActionDemo") | |
t, err = t.Parse(defineDemo) | |
if err != nil { | |
fmt.Println("parsing failed: %s", err) | |
} | |
err = t.ExecuteTemplate(os.Stdout, "a", nil) | |
if err != nil { | |
fmt.Println("execution failed: %s", err) | |
} | |
fmt.Println() | |
err = t.ExecuteTemplate(os.Stdout, "b", nil) | |
if err != nil { | |
fmt.Println("execution failed: %s", err) | |
} | |
} |
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
c:\medium\src>go build defineActionDemo.go | |
c:\medium\src>defineActionDemo | |
Template A | |
Template B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment