mux

package module
v0.0.0-...-0ec210a Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

MUX

GoDoc LICENSE

Installation

The only requirement is the Go Programming Language

go get -u github.com/forgoer/mux

Quick start

package main

import (
    "fmt"
	"http"

	"github.com/forgoer/mux"
)

func main() {
	m := mux.New()
	m.HandleFunc("/", HomeHandler)
	m.HandleFunc("/products", ProductsHandler)
	m.HandleFunc("/articles", ArticlesHandler)
	http.ListenAndServe(":8080", &m)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(accounts Accounts) http.HandlerFunc

BasicAuth returns a Basic HTTP Authorization middleware. It takes as argument a map[string]string where the key is the user name and the value is the password.

func BasicAuthForRealm

func BasicAuthForRealm(accounts Accounts, realm string) http.HandlerFunc

BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as arguments a map[string]string where the key is the user name and the value is the password, as well as the name of the Realm. If the realm is empty, "Authorization Required" will be used by default. (see http://tools.ietf.org/html/rfc2617#section-1.2)

func Stop

func Stop(r *http.Request)

func Stopped

func Stopped(r *http.Request) bool

Types

type Accounts

type Accounts map[string]string

Accounts defines a key/value for user/pass list of authorized logins.

type Handlers

type Handlers []http.Handler

Handlers A collection of http.Handler responds to an HTTP request.

func (Handlers) ServeHTTP

func (hs Handlers) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP calls f(w, r).

type Mux

type Mux struct {
	http.ServeMux
	// contains filtered or unexported fields
}

Mux is an HTTP request multiplexer.

func (*Mux) After

func (mux *Mux) After(handler func(w http.ResponseWriter, r *http.Request))

After set the handler after all handlers.

func (*Mux) Before

func (mux *Mux) Before(handler func(w http.ResponseWriter, r *http.Request))

Before set the handler before all handlers.

func (*Mux) Handle

func (mux *Mux) Handle(pattern string, handlers ...http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (*Mux) HandleFunc

func (mux *Mux) HandleFunc(pattern string, handlerFuns ...func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*Mux) Recover

func (mux *Mux) Recover(handler func(w http.ResponseWriter, r *http.Request))

Recover set the recover handler

func (*Mux) ServeHTTP

func (mux *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

Jump to

Keyboard shortcuts

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