tech:go_lang_-_template_-_gotemplate

Go lang - template - gotemplate

// Source - https://stackoverflow.com/a/59083271
// Posted by wasmup, modified by community. See post 'Timeline' for change history
// Retrieved 2026-05-03, License - CC BY-SA 4.0
 
package main
 
import (
    "fmt"
    "os"
    "text/template"
)
 
func main() {
    name := "AlphaGo"
 
    fmt.Printf("I am %s\n", name)
 
    t := template.Must(template.New("my").Parse("I am {{.Name}}\n"))
    t.Execute(os.Stdout, struct{ Name string }{name}) // I am AlphaGo
 
    t2 := template.Must(template.New("my").Parse("I am {{.name}}\n"))
    t2.Execute(os.Stdout, map[string]string{"name": name}) // I am AlphaGo
 
    t3 := template.Must(template.New("my").Parse("I am {{.}}\n"))
    t3.Execute(os.Stdout, name) // I am AlphaGo
}

FIXME

tech/go_lang_-_template_-_gotemplate.txt · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki