mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:55:28 +08:00
add chapter 15.7 (#683)
This commit is contained in:
23
eBook/examples/chapter_15/template_validation.go
Normal file
23
eBook/examples/chapter_15/template_validation.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// template_validation.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"text/template"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tOk := template.New("ok")
|
||||
//a valid template, so no panic with Must:
|
||||
template.Must(tOk.Parse("/* and a comment */ some static text: {{ .Name }}"))
|
||||
fmt.Println("The first one parsed OK.")
|
||||
fmt.Println("The next one ought to fail.")
|
||||
tErr := template.New("error_template")
|
||||
template.Must(tErr.Parse(" some static text {{ .Name }"))
|
||||
}
|
||||
|
||||
/* Output:
|
||||
The first one parsed OK.
|
||||
The next one ought to fail.
|
||||
panic: template: error_template:1: unexpected "}" in command
|
||||
*/
|
Reference in New Issue
Block a user