Golang 重置服务 post 方法 post 数据未定义

我正在使用 google golang reset 服务,当我尝试运行此代码时,post 方法出现问题,它显示 post 数据未定义


    package main


import (

    "code.google.com/p/gorest"

    "fmt"

    "net/http"

)


type Invitation struct {

    User string

}


//Service Definition

type 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

请帮忙解决这个问题


白衣非少年
浏览 181回答 2
2回答

ibeautiful

func (serv HelloService) Posted(posted User) {    fmt.Println(User)}应该func (serv HelloService) Posted(posted User) {    fmt.Println(posted)}Posted 方法接受一个名为posted 和User 类型的参数。你应该打印实际的参数,而不是它的类型 - 就像你在这里func (serv HelloService) SayHello(name string) string {    return "Hello " + name}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go