mux

package
v0.0.0-...-acf328e Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

mux

mux implements an HTTP multiplexer/router.

Documentation

Package mux

TYPES

type Mux struct {
    // Has unexported fields.
}
    Mux ...

func New(routes []*Route) *Mux
    New returns a new *Mux

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

type Route struct {
    Path, Method string
    Handler      http.Handler
}
    Route ...

Tests

Documentation

Overview

Package mux implements an HTTP multiplexer/router

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux ...

func New

func New(routes []*Route) *Mux

New returns a new *Mux

func (*Mux) ServeHTTP

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

ServeHTTP

func (mux *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var slash bool
	p := r.URL.Path
	for {
		m, ok := mux.m[p]
		if !ok {
			if p != "/" {
				p = cut(p, slash)
				slash = !slash
				continue
			}
			mux.handleError(w, http.StatusNotFound)
			return
		}
		h, ok := m[r.Method]
		if !ok {
			mux.handleError(w, http.StatusMethodNotAllowed)
			return
		}
		h.Handler.ServeHTTP(w, r)
		return
	}
}

type Route

type Route struct {
	Path, Method string
	Handler      http.Handler
}

Route ...

Jump to

Keyboard shortcuts

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