vendor dependencies with dep
This commit is contained in:
parent
93d8310491
commit
1384296a47
2712 changed files with 965742 additions and 0 deletions
35
vendor/github.com/go-chi/chi/_examples/custom-handler/main.go
generated
vendored
Normal file
35
vendor/github.com/go-chi/chi/_examples/custom-handler/main.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
type Handler func(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if err := h(w, r); err != nil {
|
||||
// handle returned error here.
|
||||
w.WriteHeader(503)
|
||||
w.Write([]byte("bad"))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := chi.NewRouter()
|
||||
r.Method("GET", "/", Handler(customHandler))
|
||||
http.ListenAndServe(":3333", r)
|
||||
}
|
||||
|
||||
func customHandler(w http.ResponseWriter, r *http.Request) error {
|
||||
q := r.URL.Query().Get("err")
|
||||
|
||||
if q != "" {
|
||||
return errors.New(q)
|
||||
}
|
||||
|
||||
w.Write([]byte("foo"))
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue