multiplexer

package module
v0.0.0-...-02ed598 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: BSD-3-Clause Imports: 7 Imported by: 1

README

Multiplexer

Install

go get -u github.com/inaohiro/go-multiplexer

Examples

package main

import (
        "log"
        "net/http"

        multiplexer "github.com/inaohiro/go-multiplexer"
)

func handler(w http.ResponseWriter, r *http.Request) {
        _, _ = w.Write([]byte("hello"))
}

func main() {
        m := multiplexer.NewMultiplexer()
        // you can define your routes with method, path and handler
        m.GET("/users", handler)
        m.POST("/users", handler)

        // of course, use can use HandleFunc
        m.HandleFunc("/", handler)

        log.Fatal(http.ListenAndServe(":8080", m))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Multiplexer

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

func NewMultiplexer

func NewMultiplexer() *Multiplexer

NewMultiplexer allocates and returns a new Multiplexer.

func (*Multiplexer) DELETE

func (mux *Multiplexer) DELETE(path string, h http.HandlerFunc)

func (*Multiplexer) Debug

func (mux *Multiplexer) Debug()

func (*Multiplexer) GET

func (mux *Multiplexer) GET(path string, h http.HandlerFunc)

func (*Multiplexer) HEAD

func (mux *Multiplexer) HEAD(path string, h http.HandlerFunc)

func (*Multiplexer) Handle

func (mux *Multiplexer) Handle(path string, handler http.Handler)

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

func (*Multiplexer) HandleFunc

func (mux *Multiplexer) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*Multiplexer) Handler

func (mux *Multiplexer) Handler(r *http.Request) (h http.Handler, pattern string)

Handler returns the handler to use for the given request, consulting r.Method, r.Host, and r.URL.Path. It always returns a non-nil handler. If the path is not in its canonical form, the handler will be an internally-generated handler that redirects to the canonical path.

Handler also returns the registered pattern that matches the request or, in the case of internally-generated redirects, the pattern that will match after following the redirect.

If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.

func (*Multiplexer) OPTIONS

func (mux *Multiplexer) OPTIONS(path string, h http.HandlerFunc)

func (*Multiplexer) PATCH

func (mux *Multiplexer) PATCH(path string, h http.HandlerFunc)

func (*Multiplexer) POST

func (mux *Multiplexer) POST(path string, h http.HandlerFunc)

func (*Multiplexer) PUT

func (mux *Multiplexer) PUT(path string, h http.HandlerFunc)

func (*Multiplexer) ServeHTTP

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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