mux

package module
v0.0.0-...-c01aa9c Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2016 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mux

Build Status Coverage Status

HTTP mux for Go.

Installation

go get -u github.com/go-http-utils/mux

Documentation

API documentation can be found here: https://godoc.org/github.com/go-http-utils/mux

Usage

import (
  "github.com/go-http-utils/mux"
)
m := mux.New()

m.Get("/:type(a|b)/:id", mux.HandlerFunc(func(res http.ResponseWriter, req *http.Request, params map[string]string) {
  res.WriteHeader(http.StatusOK)

  fmt.Println(params["type"])
  fmt.Println(params[":id"])

  res.Write([]byte("Hello Worlkd"))
}))

http.ListenAndServe(":8080", m)

Documentation

Overview

Example
package main

import (
	"fmt"
	"net/http"

	"github.com/go-http-utils/mux"
)

func main() {
	m := mux.New()

	m.Get("/:type(a|b)/:id", mux.HandlerFunc(func(res http.ResponseWriter, req *http.Request, params map[string]string) {
		res.WriteHeader(http.StatusOK)

		fmt.Println(params["type"])
		fmt.Println(params[":id"])

		res.Write([]byte("Hello Worlkd"))
	}))

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

Index

Examples

Constants

View Source
const Version = "0.1.0"

Version is this package's version number.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request, map[string]string)
}

Handler likes the http.Handler but with the URL named params support.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request, map[string]string)

The HandlerFunc type is an adapter to allow the use of an ordinary function as a Handler.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(res http.ResponseWriter, req *http.Request, params map[string]string)

type Mux

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

Mux is the HTTP request multiplexer.

func New

func New() *Mux

New returns a new mux.

func (*Mux) Delete

func (m *Mux) Delete(url string, handler Handler) *Mux

Delete registers a handler for the DELETE http method.

func (*Mux) Get

func (m *Mux) Get(url string, handler Handler) *Mux

Get registers a handler for the GET http method.

func (*Mux) Handle

func (m *Mux) Handle(method string, url string, handler Handler) *Mux

Handle registers the handler for the given method and url.

func (*Mux) Head

func (m *Mux) Head(url string, handler Handler) *Mux

Head registers a handler for the HEAD http method.

func (*Mux) Patch

func (m *Mux) Patch(url string, handler Handler) *Mux

Patch registers a handler for the PATCH http method.

func (*Mux) Post

func (m *Mux) Post(url string, handler Handler) *Mux

Post registers a handler for the POST http method.

func (*Mux) Put

func (m *Mux) Put(url string, handler Handler) *Mux

Put registers a handler for the PUT http method.

func (Mux) ServeHTTP

func (m Mux) ServeHTTP(res http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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