当我试图运行我的应用程序,它说,有一个意外}
在第32行,我已经算{
和}
,似乎他们甚至但当我删除F1,F2和P效果很好。我怎样才能解决这个问题?
package main
import (
"fmt"
"log"
"net/http"
"html/template"
)
type friend struct{
fname string
}
type person struct{
username string
emails []string
friends []*friend
}
func home(w http.ResponseWriter, r *http.Request){
f1 := friend{fname: "minux.ma"}
f2 := friend{fname: "xushiwei"}
p := Person{
userName: "Astaxie",
emails: []string{"[email protected]", "[email protected]"},
friends: []*Friend{&f1, &f2}
}
t, err := template.ParseFiles("template.gtpl")
if err != nil{
fmt.Println(err)
}
t.Execute(w, nil)
}
func main(){
http.HandleFunc("/", home)
err := http.ListenAndServe(":8000", nil)
if err != nil{
log.Fatal("listen and serve:", err)
}
}
发生了意外情况}
,因为您friends
在行尾缺少逗号
friends: []*Friend{&f1, &f2},
始终是go fmt
您的代码。(或使用goimports
)。它将给您与确切的行和列错误:
在复合文字中的换行符前缺少“,”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句