heshanindika / gorest

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

Parameter list not matching. No matching Method found for EndPoint #9

Open GoogleCodeExporter opened 8 years ago

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

import (
  "fmt"
  "net/http"
  goRest "code.google.com/p/gorest"
  rethinkDb "github.com/christopherhesse/rethinkgo"
)

func main() {
  goRest.RegisterService(new(Console)) //Register our service
  http.Handle("/", goRest.Handle())
  fmt.Printf("Web Application Listening...\n")
  http.ListenAndServe(":3000", nil)
}

//Service Definition
type Console struct {
  goRest.RestService `root:"/" consumes:"application/json" produces: "application/json"`
  getReadings        goRest.EndPoint `method:"GET" path:"/readings/" output:"[]interface{}"`
}

func (serv Console) GetReadings()([]interface{}) {
  databaseName := "test"
  tableName := "readings"
  session, _ := rethinkDb.Connect("localhost:28015", databaseName)

  var response []interface{}
  _ = rethinkDb.Table(tableName).Run(session).All(&response)
  fmt.Printf("response:", response)

  return response
}

What is the expected output? What do you see instead?
I expect to have the application startup without issue...

Instead I get this error...

$ go run console.go

2013/04/22 22:38:29 All EndPoints for service [ Console ] , registered under 
root path:  /
2013/04/22 22:38:29 Parameter list not matching. No matching Method found for 
EndPoint:[getReadings],type:[GET] . Expecting: #func(serv Console) 
GetReadings()([]interface{})# with one([]interface{}) return parameter.
panic: Parameter list not matching. No matching Method found for 
EndPoint:[getReadings],type:[GET] . Expecting: #func(serv Console) 
GetReadings()([]interface{})# with one([]interface{}) return parameter.

goroutine 1 [running]:
log.Panic(0x2500bd8, 0x100000001)
  /usr/local/go/src/pkg/log/log.go:307 +0x9f
code.google.com/p/gorest.mapFieldsToMethods(0xf84008b000, 0x1f7f18, 0x2233cc, 
0x527465670000000b, 0x22426c, ...)
  /Users/nunya/.mygo/src/code.google.com/p/gorest/reflect.go:103 +0x684
code.google.com/p/gorest.registerService(0x217c1c, 0xf800000000, 0x1f1fa8, 
0xf84006bb00, 0x1f1fa8, ...)
  /Users/nunya/.mygo/src/code.google.com/p/gorest/reflect.go:66 +0x4ad
code.google.com/p/gorest.RegisterServiceOnPath(0x217c1c, 0x0, 0x1f1fa8, 
0xf84006bb00, 0x204d, ...)
  /Users/nunya/.mygo/src/code.google.com/p/gorest/gorest.go:182 +0x116
code.google.com/p/gorest.RegisterService(0x1f1fa8, 0xf84006bb00)
  /Users/nunya/.mygo/src/code.google.com/p/gorest/gorest.go:137 +0x42
main.main()
  /Users/nunya/Projects/golang/console/console.go:15 +0x4d

goroutine 2 [syscall]:
created by runtime.main
  /usr/local/go/src/pkg/runtime/proc.c:221
exit status 2
What version of the product are you using? On what operating system?

Please provide any additional information below.

I'm not sure what else to do.  The error message seems very helpful.  Tells me 
what function it's looking for.  However, that's exactly the function I have 
defined.

Original issue reported on code.google.com by ch...@altonymous.com on 22 Apr 2013 at 10:41

GoogleCodeExporter commented 8 years ago
Sorry I left out what version I'm running.

$ go version
go version go1.0.3

OS: OS X 10.8.2 (12C60) [Mountain Lion]

Original comment by ch...@altonymous.com on 22 Apr 2013 at 10:43

GoogleCodeExporter commented 8 years ago
I have made a few changes to get away from the generic []interfaces{} type.  
I'm not longer receiving an error during compile time but instead getting one 
during runtime.  The code is below the error.

$ go run console.go

2013/04/22 23:24:37 All EndPoints for service [ Console ] , registered under 
root path:  /
2013/04/22 23:24:37 Registerd service: Console  endpoint: GET readings
Web Application Listening...
2013/04/22 23:24:43 Internal Server Error: Could not serve page:  GET /readings
2013/04/22 23:24:43 runtime error: invalid memory address or nil pointer 
dereference
2013/04/22 23:24:43 
/Users/nunya/.mygo/src/code.google.com/p/gorest/gorest.go:194 (0x4e5ec)
  google.com/p/gorest._func_001: log.Printf("%s", debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x113d0)
  panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x11e9c)
  panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/thread_darwin.c:418 (0x14feb)
  sigpanic: runtime·panicstring("invalid memory address or nil pointer dereference");
/Users/nunya/.mygo/src/code.google.com/p/gorest/util.go:61 (0x4d303)
  google.com/p/gorest.InterfaceToBytes: return m.Marshal(i)
/Users/nunya/.mygo/src/code.google.com/p/gorest/reflect.go:396 (0x4bfa4)
  google.com/p/gorest.prepareServe: if bytarr, err := InterfaceToBytes(ret[0].Interface(), servMeta.producesMime); err == nil {
/Users/nunya/.mygo/src/code.google.com/p/gorest/gorest.go:215 (0x43471)
  google.com/p/gorest.(*manager).ServeHTTP: data, state := prepareServe(ctx, ep)
/usr/local/go/src/pkg/net/http/server.go:941 (0x33f11)
  (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x32ed0)
  (*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0xf4d6)
  goexit: runtime·goexit(void)

// console.go
package main

import (
  "fmt"
  "net/http"
  goRest "code.google.com/p/gorest"
  rethinkDb "github.com/christopherhesse/rethinkgo"
)

func main() {
  goRest.RegisterService(new(Console)) //Register our service
  http.Handle("/", goRest.Handle())
  fmt.Printf("Web Application Listening...\n")
  http.ListenAndServe(":3000", nil)
}

//Service Definition
type Console struct {
  goRest.RestService `root:"/" consumes:"application/json" produces: "application/json"`
  getReadings        goRest.EndPoint `method:"GET" path:"/readings/" output:"[]Reading"`
}

type Reading struct {
  Id   string `json:"id"`
  Name string `json:"name"`
}

func (serv Console) GetReadings() []Reading {
  databaseName := "test"
  tableName := "readings"
  session, err := rethinkDb.Connect("localhost:28015", databaseName)

  if err != nil {
    fmt.Println("error connecting:", err)
  }

  // This creates a database session 'session' that may be used to run
  // queries on the server.  Queries let you read, insert, update, and
  // delete JSON objects ("rows") on the server, as well as manage tables.
  query := rethinkDb.Table(tableName)
  rows := query.Run(session)
  defer rows.Close()

  // 'rows' is an iterator that can be used to iterate over the
  // results.  If there was an error, it is available in rows.Err()
  readings := make([]Reading, 1)
  for rows.Next() {
    var row Reading
    if err = rows.Scan(&row); err != nil {
      fmt.Println("err:", err)
      break
    }

    readings = append(readings, row)
    // fmt.Println("row:", row)
  }

  // fmt.Println("readings: ", readings)
  if err = rows.Err(); err != nil {
    fmt.Println("err:", err)
  }

  return readings
}

Original comment by ch...@altonymous.com on 22 Apr 2013 at 11:26

GoogleCodeExporter commented 8 years ago
Hey Chris,

This is caused by the line: 
goRest.RestService `root:"/" consumes:"application/json" produces: 
"application/json"`

There is a space after:   "produces: "...

I think this is a bug on Go's tag parser, as we have no control over this. I 
will investigated further..

Original comment by siyabong...@gmail.com on 23 Apr 2013 at 6:53

GoogleCodeExporter commented 8 years ago
Same as issue #2

Original comment by siyabong...@gmail.com on 23 Apr 2013 at 8:37