Standard library / html/template
html/template.Must()
Returns the template on success and panics on a non-nil error. Use for trusted constant templates, not runtime user input. Expected stdout: 'Hello Ada\n'.
Formal Syntax & Structure
go syntaxgo
func Must(t *Template, err error) *TemplateParameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | *Template | Template returned by a constructor or parse call. |
| err | error | Error returned by the preceding operation. |
Return Value
*Template
Returns the template on success and panics on a non-nil error.
Working Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("greet").Parse("Hello {{.}}")) check(t.Execute(os.Stdout, "Ada")) fmt.Println()}