mx

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package mx implements a HTTP request multiplexer. It is an internal package so that we can be able to add functionality to it that is used by ong, but cannot be called by third parties. Proper documentation for users should be added to github.com/komuw/ong/mux instead.

Index

Constants

View Source
const (
	MethodAll     = "ALL"
	MethodGet     = http.MethodGet
	MethodHead    = http.MethodHead
	MethodPost    = http.MethodPost
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch
	MethodDelete  = http.MethodDelete
	MethodConnect = http.MethodConnect
	MethodOptions = http.MethodOptions
	MethodTrace   = http.MethodTrace
)

Common HTTP methods.

Variables

This section is empty.

Functions

func Param

func Param(ctx context.Context, param string) string

Param gets the path/url parameter from the specified Context.

Types

type Muxer

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

Muxer is a HTTP request multiplexer.

func New

func New(opt config.Opts, notFoundHandler http.Handler, routes ...Route) (Muxer, error)

New returns a HTTP request multiplexer that has the paths in routes.

func (Muxer) AddRoute

func (m Muxer) AddRoute(rt Route) error

AddRoute adds a new Route to an existing Mux. This is only expected to be used internally by ong. Users of ong should not use this method. Instead, pass all your routes when calling New

func (Muxer) GoString

func (m Muxer) GoString() string

GoString implements fmt.GoStringer

func (Muxer) Resolve

func (m Muxer) Resolve(path string) Route

Resolve resolves a URL path to its corresponding Route and hence http handler.

func (Muxer) ServeHTTP

func (m Muxer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements a http.Handler

func (Muxer) String

func (m Muxer) String() string

String implements fmt.Stringer

type Route

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

Route represents the pattern & http method that will be served by a particular http handler.

Use NewRoute to get a valid Route.

func NewRoute

func NewRoute(
	pattern string,
	method string,
	handler http.Handler,
) (Route, error)

NewRoute creates a new Route.

func (Route) String

func (r Route) String() string

Jump to

Keyboard shortcuts

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