Releases: lonng/nex
Releases · lonng/nex
v1.4.1
feature: handler group
Performance improvement
v1.3.0 Merge branch 'master' of https://github.com/chrislonng/nex
context.Context support
context.Context support
func main() {
logic := func(ctx context.Context) (context.Context, *testResponse, error) {
println(ctx.Value("key").(string))
println(ctx.Value("key2").(string))
return context.WithValue(ctx, "logic", "logic-value"), &testResponse{}, nil
}
before1 := func(ctx context.Context, request *http.Request) (context.Context, error) {
return context.WithValue(ctx, "key", "value"), nil
}
before2 := func(ctx context.Context, request *http.Request) (context.Context, error) {
println(ctx.Value("key").(string))
return context.WithValue(ctx, "key2", "value2"), nil
}
after1 := func(ctx context.Context, w http.ResponseWriter) (context.Context, error) {
println(ctx.Value("key").(string))
println(ctx.Value("key2").(string))
println(ctx.Value("logic").(string))
return context.WithValue(ctx, "after1", "after1-value"), nil
}
after2 := func(ctx context.Context, w http.ResponseWriter) (context.Context, error) {
println(ctx.Value("key").(string))
println(ctx.Value("key2").(string))
println(ctx.Value("logic").(string))
println(ctx.Value("after1").(string))
return context.WithValue(ctx, "key", "value"), nil
}
handler := Handler(logic).Before(before1, before2).After(after1, after2)
handler.ServeHTTP(w, r)
}
middleware support
- middleware support
- helper method for url.Values