fix: coding style and file format for chapter 11, 12, 13, 14 and 15.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:32:16 +08:00
parent c5413075c1
commit 4abbfabb52
63 changed files with 2662 additions and 2622 deletions

View File

@@ -1,29 +1,30 @@
// template_validation_recover.go
package main
import (
"text/template"
"fmt"
"log"
)
func main() {
tOk := template.New("ok")
tErr := template.New("error_template")
defer func() {
if err := recover(); err != nil {
log.Printf("run time panic: %v", err)
}
}()
//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.")
template.Must(tErr.Parse(" some static text {{ .Name }"))
}
/* Output:
The first one parsed OK.
The next one ought to fail.
2011/10/27 10:56:27 run time panic: template: error_template:1: unexpected "}" in command
*/
// template_validation_recover.go
package main
import (
"fmt"
"log"
"text/template"
)
func main() {
tOk := template.New("ok")
tErr := template.New("error_template")
defer func() {
if err := recover(); err != nil {
log.Printf("run time panic: %v", err)
}
}()
//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.")
template.Must(tErr.Parse(" some static text {{ .Name }"))
}
/* Output:
The first one parsed OK.
The next one ought to fail.
2011/10/27 10:56:27 run time panic: template: error_template:1: unexpected "}" in command
*/