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

Extending web.Context #164

Open
marconi opened this issue Sep 28, 2013 · 2 comments
Open

Extending web.Context #164

marconi opened this issue Sep 28, 2013 · 2 comments

Comments

@marconi
Copy link

marconi commented Sep 28, 2013

I found myself repeating the following:

ctx.WriteHeader(400)

// or

ctx.WriteHeader(200)
ctx.Write([]byte(somedata))

so i ember the context instead:

type Context struct {
    *web.Context
}

func (ctx *web.Context) BadRequest() {
    ctx.WriteHeader(400)
}

func (ctx *web.Context) Ok(data []byte) {
    ctx.WriteHeader(200)
    ctx.Write(data)
}

so I can do like:

func (ctx *Context) index() {
    ctx.BadRequest()
}

but I'm getting the following errors:

2013/09/29 05:20:01 web.go serving localhost:9999
2013/09/29 05:20:05 Handler crashed with error reflect: Call with too few input arguments
2013/09/29 05:20:05 /usr/local/go/src/pkg/runtime/panic.c 248
2013/09/29 05:20:05 /usr/local/go/src/pkg/reflect/value.go 397
2013/09/29 05:20:05 /usr/local/go/src/pkg/reflect/value.go 345
2013/09/29 05:20:05 /Users/marconi/go/src/github.com/hoisie/web/server.go 216
2013/09/29 05:20:05 /Users/marconi/go/src/github.com/hoisie/web/server.go 361
2013/09/29 05:20:05 /Users/marconi/go/src/github.com/hoisie/web/server.go 94
2013/09/29 05:20:05 /Users/marconi/go/src/github.com/hoisie/web/server.go 89
2013/09/29 05:20:05 /usr/local/go/src/pkg/net/http/server.go 1494
2013/09/29 05:20:05 /usr/local/go/src/pkg/net/http/server.go 1595
2013/09/29 05:20:05 /usr/local/go/src/pkg/net/http/server.go 1165
2013/09/29 05:20:05 /usr/local/go/src/pkg/runtime/proc.c 1389
@kitto86
Copy link

kitto86 commented Nov 3, 2013

I've started playing with web and I've seen that type of error when I did like this:

  func main() {
    web.Get("/hello", hello)
    web.Run("0.0.0.0:9999")
  }

  func hello(val string) string {
    return "hello " + val
  }

In the code above the handler hello expects one argument, but that is not provided since the regexp has not any defined group. To fix I've done so:

  func main() {
    web.Get("/(hello)", hello)
    web.Run("0.0.0.0:9999")
  }

I hope it helps.

@marconi
Copy link
Author

marconi commented Nov 3, 2013

@kitto86 we have different issues, my problem here involves creating custom context by embedding web.Context. Anyway, this framework doesn't seem active anymore. I've long since moved to GoWeb which is a more lightweight and flexible framework.

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

2 participants