Skip to content

Navigation Menu

Sign up
vinxiPublic

About

Unobstructive context implementation for request-aware data sharing (merged into vinxi/vinxi)

Resources

Stars

0 stars

Watchers

2 watching

Forks

Repository files navigation

Note: merged into vinxi/vinxi.

context package implements a simple, unobstructive context for request-aware data sharing across a middleware pipeline.

Originally based in nbio/httpcontext.

Installation

go get -u gopkg.in/vinxi/context.v0

API

See godoc reference.

Example

package main
import (
 "fmt"
 "gopkg.in/vinxi/context.v0"
 "gopkg.in/vinxi/vinxi.v0"
 "net/http"
)
func main() {
 fmt.Printf("Server listening on port: %d\n", 3100)
 vs := vinxi.NewServer(vinxi.ServerOptions{Host: "localhost", Port: 3100})
 vs.Use(func(w http.ResponseWriter, r *http.Request, h http.Handler) {
 context.Set(r, "foo", "bar")
 h.ServeHTTP(w, r)
 })
 vs.Use(func(w http.ResponseWriter, r *http.Request, h http.Handler) {
 w.Header().Set("foo", context.GetString(r, "foo"))
 h.ServeHTTP(w, r)
 })
 vs.Forward("http://httpbin.org")
 err := vs.Listen()
 if err != nil {
 fmt.Errorf("Error: %s\n", err)
 }
}

License

MIT

About

Unobstructive context implementation for request-aware data sharing (merged into vinxi/vinxi)

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /