Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PANIC Value not found for type *web.Context #2

Open
xyproto opened this issue May 9, 2014 · 3 comments
Open

PANIC Value not found for type *web.Context #2

xyproto opened this issue May 9, 2014 · 3 comments

Comments

@xyproto
Copy link

xyproto commented May 9, 2014

Hi,

The "martini" branch in one of my repositories has an example application that panics when visited, that did not panic with hoisie/web:

https://github.com/xyproto/browserspeak/tree/martini

One way of trying it out

go get github.com/martini-contrib/web
go get github.com/go-martini/martini
mkdir -p $GOPATH/src/github.com/xyproto
cd $GOPATH/src/github.com/xyproto
git clone https://github.com/xyproto/browserspeak.git -b martini
cd browserspeak/example
go build
PORT=8080 ./example

Visiting http://localhost:8080/test.svg works, but http://localhost:8080/ gives the following backtrace:

PANIC

Value not found for type *web.Context

/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/router.go:352 (0x43dd08)
    (*routeContext).run: panic(err)
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/router.go:229 (0x43d102)
    (*route).Handle: context.run()
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/router.go:112 (0x43c13c)
    (*router).Handle: route.Handle(context, res)
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:111 (0x43e5d0)
    Router.Handle.fm: m.Action(r.Handle)
/opt/go/src/pkg/runtime/asm_amd64.s:340 (0x4242b2)
    call64: CALLFN(call64, 64)
/opt/go/src/pkg/reflect/value.go:474 (0x464fbb)
    Value.call: call(fn, ptr, uint32(size))
/opt/go/src/pkg/reflect/value.go:345 (0x4640ad)
    Value.Call: return v.call("Call", in)
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/codegangsta/inject/inject.go:102 (0x4b0ff4)
    (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:165 (0x43a742)
    (*context).run: _, err := c.Invoke(c.handler())
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:156 (0x43a69b)
    (*context).Next: c.run()
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/recovery.go:140 (0x43eaf6)
    func.004: c.Next()
/opt/go/src/pkg/runtime/asm_amd64.s:339 (0x424252)
    call32: CALLFN(call32, 32)
/opt/go/src/pkg/reflect/value.go:474 (0x464fbb)
    Value.call: call(fn, ptr, uint32(size))
/opt/go/src/pkg/reflect/value.go:345 (0x4640ad)
    Value.Call: return v.call("Call", in)
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/codegangsta/inject/inject.go:102 (0x4b0ff4)
    (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:165 (0x43a742)
    (*context).run: _, err := c.Invoke(c.handler())
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:156 (0x43a69b)
    (*context).Next: c.run()
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/logger.go:25 (0x43e392)
    func.001: c.Next()
/opt/go/src/pkg/runtime/asm_amd64.s:340 (0x4242b2)
    call64: CALLFN(call64, 64)
/opt/go/src/pkg/reflect/value.go:474 (0x464fbb)
    Value.call: call(fn, ptr, uint32(size))
/opt/go/src/pkg/reflect/value.go:345 (0x4640ad)
    Value.Call: return v.call("Call", in)
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/codegangsta/inject/inject.go:102 (0x4b0ff4)
    (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:165 (0x43a742)
    (*context).run: _, err := c.Invoke(c.handler())
/uio/kant/usit-uait-u1/rodseth/go/src/github.com/go-martini/martini/martini.go:69 (0x439a63)
    (*Martini).ServeHTTP: m.createContext(res, req).run()
/opt/go/src/pkg/net/http/server.go:1597 (0x48a26e)
    serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/opt/go/src/pkg/net/http/server.go:1167 (0x488277)
    (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/opt/go/src/pkg/runtime/proc.c:1394 (0x417ab0)
    goexit: runtime·goexit(void)

I can not see any references to my own code, so I'm having a hard time pinpointing where this error lies. Any help is appreciated.

Best regards,
Alexander Rødseth
@Gissues:{"order":50,"status":"done"}

@mickelsonm
Copy link

Hi @xyproto ! I think you may have overlooked a couple things with your code.

Here's how you have to go about using *web.Context, which in your case didn't have value because you didn't use it! :)

See example below:

    func svgGenerator(ctx *web.Context){
        page := svgPage()
        ctx.WriteString(page.String())
    }

    func defaultHandler(ctx *web.Context){
        ctx.WriteString("TODO: Implement me!")
    }

    func main() {
        fmt.Println("BrowserSpeak Version:", browserspeak.Version)

        m := martini.Classic()
        m.Use(web.ContextWithCookieSecret(""))

        // Connect /test.svg with svgGenerator
        m.Get("/test", svgGenerator)

        //TODO: implement a root handler
        m.Get("/", defaultHandler)

        m.Run()
    }

Also, make sure to implement a root handler! It doesn't know how to handle / on its own...

Hope this helps!

@xyproto
Copy link
Author

xyproto commented May 18, 2014

Thank you! I will look into this.

@insionng
Copy link

cannot get req.URL.Query() 's any value from ctx.Params ? I mean martini.Params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants