mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
go dep
Migrated from plain /vendor to go dep
This commit is contained in:
parent
0262763c95
commit
fd693f4ff4
957 changed files with 36866 additions and 177595 deletions
60
vendor/github.com/codegangsta/negroni/negroni.go
generated
vendored
60
vendor/github.com/codegangsta/negroni/negroni.go
generated
vendored
|
@ -6,6 +6,11 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultAddress is used if no other is specified.
|
||||
DefaultAddress = ":8080"
|
||||
)
|
||||
|
||||
// Handler handler is an interface that objects can implement to be registered to serve as middleware
|
||||
// in the Negroni middleware stack.
|
||||
// ServeHTTP should yield to the next middleware in the chain by invoking the next http.HandlerFunc
|
||||
|
@ -43,6 +48,16 @@ func Wrap(handler http.Handler) Handler {
|
|||
})
|
||||
}
|
||||
|
||||
// WrapFunc converts a http.HandlerFunc into a negroni.Handler so it can be used as a Negroni
|
||||
// middleware. The next http.HandlerFunc is automatically called after the Handler
|
||||
// is executed.
|
||||
func WrapFunc(handlerFunc http.HandlerFunc) Handler {
|
||||
return HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
handlerFunc(rw, r)
|
||||
next(rw, r)
|
||||
})
|
||||
}
|
||||
|
||||
// Negroni is a stack of Middleware Handlers that can be invoked as an http.Handler.
|
||||
// Negroni middleware is evaluated in the order that they are added to the stack using
|
||||
// the Use and UseHandler methods.
|
||||
|
@ -59,6 +74,14 @@ func New(handlers ...Handler) *Negroni {
|
|||
}
|
||||
}
|
||||
|
||||
// With returns a new Negroni instance that is a combination of the negroni
|
||||
// receiver's handlers and the provided handlers.
|
||||
func (n *Negroni) With(handlers ...Handler) *Negroni {
|
||||
return New(
|
||||
append(n.handlers, handlers...)...,
|
||||
)
|
||||
}
|
||||
|
||||
// Classic returns a new Negroni instance with the default middleware already
|
||||
// in the stack.
|
||||
//
|
||||
|
@ -75,25 +98,52 @@ func (n *Negroni) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Use adds a Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni.
|
||||
func (n *Negroni) Use(handler Handler) {
|
||||
if handler == nil {
|
||||
panic("handler cannot be nil")
|
||||
}
|
||||
|
||||
n.handlers = append(n.handlers, handler)
|
||||
n.middleware = build(n.handlers)
|
||||
}
|
||||
|
||||
// UseFunc adds a Negroni-style handler function onto the middleware stack.
|
||||
func (n *Negroni) UseFunc(handlerFunc func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)) {
|
||||
n.Use(HandlerFunc(handlerFunc))
|
||||
}
|
||||
|
||||
// UseHandler adds a http.Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni.
|
||||
func (n *Negroni) UseHandler(handler http.Handler) {
|
||||
n.Use(Wrap(handler))
|
||||
}
|
||||
|
||||
// UseHandlerFunc adds a http.HandlerFunc-style handler function onto the middleware stack.
|
||||
func (n *Negroni) UseHandlerFunc(handlerFunc func(rw http.ResponseWriter, r *http.Request)) {
|
||||
n.UseHandler(http.HandlerFunc(handlerFunc))
|
||||
}
|
||||
|
||||
// Run is a convenience function that runs the negroni stack as an HTTP
|
||||
// server. The addr string takes the same format as http.ListenAndServe.
|
||||
func (n *Negroni) Run(addr string) {
|
||||
// server. The addr string, if provided, takes the same format as http.ListenAndServe.
|
||||
// If no address is provided but the PORT environment variable is set, the PORT value is used.
|
||||
// If neither is provided, the address' value will equal the DefaultAddress constant.
|
||||
func (n *Negroni) Run(addr ...string) {
|
||||
l := log.New(os.Stdout, "[negroni] ", 0)
|
||||
l.Printf("listening on %s", addr)
|
||||
l.Fatal(http.ListenAndServe(addr, n))
|
||||
finalAddr := detectAddress(addr...)
|
||||
l.Printf("listening on %s", finalAddr)
|
||||
l.Fatal(http.ListenAndServe(finalAddr, n))
|
||||
}
|
||||
|
||||
func detectAddress(addr ...string) string {
|
||||
if len(addr) > 0 {
|
||||
return addr[0]
|
||||
}
|
||||
if port := os.Getenv("PORT"); port != "" {
|
||||
return ":" + port
|
||||
}
|
||||
return DefaultAddress
|
||||
}
|
||||
|
||||
// Returns a list of all the handlers in the current Negroni middleware chain.
|
||||
func (n *Negroni) Handlers() ([]Handler) {
|
||||
func (n *Negroni) Handlers() []Handler {
|
||||
return n.handlers
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue