mux

package
v0.0.0-...-f999dd2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mux is a wrapper over goji.Mux

It adds a predefined list of middlewares to muxes and sub-muxes that would be created via the New() and Sub() functions

e.g. usage

acslog := log.NewJSONLogger(conf.Log.Access)
errlog := log.NewJSONLogger(conf.Log.Err)
mux.Init(acslog, errlog)

To set custom middleware like logger, 404, metrics and 404 handlers to all muxes, use

acslog := log.NewJSONLogger(conf.Log.Access)
errlog := log.NewJSONLogger(conf.Log.Err)
mux.SetLogs(acslog, errlog)

mux.SetSubMware(
		middleware.ApplySubStats,
		middleware.Apply404)

mux.SetMware(
	middleware.ApplyLog(acsslog),
	middleware.Apply404,
	middleware.ApplyStats,
	middleware.ApplyReqID)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(acslog, errlog log.Logger)

Init initializes the mux package. It initializes the middlewares to be used by Muxes & SubMuxes and sets the loggers. An application can overwrite the middlewares by calling SetMware & SetSubMware

func SetLogs

func SetLogs(a, e log.Logger)

SetLogs sets the loggers used by the mux package

func SetMware

func SetMware(m ...func(goji.Handler) goji.Handler)

SetMware sets the middlewares to be used for all muxes

func SetSubMware

func SetSubMware(m ...func(goji.Handler) goji.Handler)

SetSubMware sets the middlewares to be used for all sub-muxes

Types

type Mux

type Mux struct {
	*goji.Mux
}

Mux is a wrapper over Goji's mux

func New

func New() *Mux

New is a wrapper over goji.NewMux(). It adds the pre-defined list of middlewares to the mux

func Sub

func Sub() *Mux

Sub is a wrapper over goji.SubMux(). It adds the pre-defined list of middlewares to the submux

func (*Mux) Delete

func (m *Mux) Delete(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Delete dispatches to the given handler when the pattern matches and the HTTP method is DELETE.

func (*Mux) Get

func (m *Mux) Get(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Get dispatches to the given handler when the pattern matches and the HTTP method is GET.

func (*Mux) Head

func (m *Mux) Head(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Head dispatches to the given handler when the pattern matches and the HTTP method is HEAD.

func (*Mux) Options

func (m *Mux) Options(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Options dispatches to the given handler when the pattern matches and the HTTP method is OPTIONS.

func (*Mux) Patch

func (m *Mux) Patch(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Patch dispatches to the given handler when the pattern matches and the HTTP method is PATCH.

func (*Mux) Post

func (m *Mux) Post(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Post dispatches to the given handler when the pattern matches and the HTTP method is POST.

func (*Mux) Put

func (m *Mux) Put(pattern string, h func(context.Context, http.ResponseWriter, *http.Request) error)

Put dispatches to the given handler when the pattern matches and the HTTP method is PUT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL