xShaneSong / gorest

Automatically exported from code.google.com/p/gorest
0 stars 0 forks source link

Can't add other variables into service struct #19

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Slight modification of the tutorial to add a configuration variable into the 
service:

package main

import (
    "code.google.com/p/gorest"
    "net/http"
)

func main() {
    hello := HelloService{greeting: "Nice to see you, "}

    gorest.RegisterService(&hello) //Register our service
    http.Handle("/", gorest.Handle())
    http.ListenAndServe(":8787", nil)
}

//Service Definition
type HelloService struct {
    greeting           string
    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"`
}

func (serv HelloService) HelloWorld() string {
    return "Hello World"
}
func (serv HelloService) SayHello(name string) string {
    return serv.greeting + name
}

What is the expected output? What do you see instead?

When I go to: http://localhost:8787/tutorial/hello/andrew I expect to see "Nice 
to see you, andrew", but instead I just see "andrew"

Is gorest doing something that prevents me doing this?

Original issue reported on code.google.com by stock.an...@gmail.com on 12 Jun 2015 at 1:15