Documentation ¶
Overview ¶
Example ¶
package main import ( "net/http" "github.com/johejo/gomple" ) func handle(w http.ResponseWriter, r *http.Request) error { return nil } func main() { // with http.NewServeMux g := gomple.New() mux := http.NewServeMux() mux.HandleFunc("/", g.WrapFunc(handle)) }
Output:
Index ¶
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
- type ErrorHandler
- type Gomple
- type HandlerFunc
- type Mux
- func (m *Mux) Connect(pattern string, h HandlerFunc)
- func (m *Mux) Delete(pattern string, h HandlerFunc)
- func (m *Mux) Get(pattern string, h HandlerFunc)
- func (m *Mux) Gomple() *Gomple
- func (m *Mux) HandleFunc(pattern string, h HandlerFunc)
- func (m *Mux) Head(pattern string, h HandlerFunc)
- func (m *Mux) Options(pattern string, h HandlerFunc)
- func (m *Mux) Post(pattern string, h HandlerFunc)
- func (m *Mux) Put(pattern string, h HandlerFunc)
- func (m *Mux) Raw() *chi.Mux
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Trace(pattern string, h HandlerFunc)
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
Types ¶
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
type Gomple ¶
type Gomple struct {
// contains filtered or unexported fields
}
func (*Gomple) WrapFunc ¶
func (g *Gomple) WrapFunc(h HandlerFunc) http.HandlerFunc
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "encoding/json" "log" "net/http" "github.com/johejo/gomple" ) func errHandler(w http.ResponseWriter, r *http.Request, err error) { if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) } } func main() { g := gomple.New(gomple.WithErrorHandler(errHandler)) c := &controller{gomple: g} mux := gomple.NewMuxWithGomple(g) mux.Post("/users", c.createUser) } type controller struct { gomple *gomple.Gomple } type User struct { ID string `json:"id"` Name string `json:"name"` } func (c *controller) createUser(w http.ResponseWriter, r *http.Request) error { var u User if err := json.NewDecoder(r.Body).Decode(&u); err != nil { return err } log.Println(u) w.WriteHeader(http.StatusCreated) return nil }
Output:
func NewMuxWithGomple ¶
func (*Mux) Connect ¶
func (m *Mux) Connect(pattern string, h HandlerFunc)
func (*Mux) Delete ¶
func (m *Mux) Delete(pattern string, h HandlerFunc)
func (*Mux) Get ¶
func (m *Mux) Get(pattern string, h HandlerFunc)
func (*Mux) HandleFunc ¶
func (m *Mux) HandleFunc(pattern string, h HandlerFunc)
func (*Mux) Head ¶
func (m *Mux) Head(pattern string, h HandlerFunc)
func (*Mux) Options ¶
func (m *Mux) Options(pattern string, h HandlerFunc)
func (*Mux) Post ¶
func (m *Mux) Post(pattern string, h HandlerFunc)
func (*Mux) Put ¶
func (m *Mux) Put(pattern string, h HandlerFunc)
func (*Mux) Trace ¶
func (m *Mux) Trace(pattern string, h HandlerFunc)
type Option ¶
type Option func(cfg *config)
func WithErrorHandler ¶
func WithErrorHandler(eh ErrorHandler) Option
Click to show internal directories.
Click to hide internal directories.