我正在使用 google golang reset 服務(wù),當(dāng)我嘗試運行此代碼時,post 方法出現(xiàn)問題,它顯示 post 數(shù)據(jù)未定義 package mainimport ( "code.google.com/p/gorest" "fmt" "net/http")type Invitation struct { User string}//Service Definitiontype HelloService struct { gorest.RestService //gorest.RestService `root:"/tutorial/"` helloWorld gorest.EndPoint `method:"GET" path:"/hello-world/" output:"string"` sayHello gorest.EndPoint `method:"GET" path:"/hello/{name:string}" output:"string"` posted gorest.EndPoint `method:"POST" path:"/post/" postdata:"User" `}func main() { gorest.RegisterService(new(HelloService)) //Register our service http.Handle("/", gorest.Handle()) http.ListenAndServe(":8787", nil)}func (serv HelloService) Posted(posted User) { fmt.Println(User)}func (serv HelloService) HelloWorld() string { return "Hello World"}func (serv HelloService) SayHello(name string) string { return "Hello " + name}這是我得到的錯誤# command-line-arguments./registation.go:28: undefined: User./registation.go:29: undefined: User請幫忙解決這個問題
2 回答

ibeautiful
TA貢獻1993條經(jīng)驗 獲得超6個贊
func (serv HelloService) Posted(posted User) {
fmt.Println(User)
}
應(yīng)該
func (serv HelloService) Posted(posted User) {
fmt.Println(posted)
}
Posted 方法接受一個名為posted 和User 類型的參數(shù)。
你應(yīng)該打印實際的參數(shù),而不是它的類型 - 就像你在這里
func (serv HelloService) SayHello(name string) string {
return "Hello " + name
}
- 2 回答
- 0 關(guān)注
- 205 瀏覽
添加回答
舉報
0/150
提交
取消