Open GoogleCodeExporter opened 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
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
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
Same as issue #2
Original comment by siyabong...@gmail.com
on 23 Apr 2013 at 8:37
Original issue reported on code.google.com by
ch...@altonymous.com
on 22 Apr 2013 at 10:41