muxlist

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

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

Go to latest
Published: Nov 16, 2018 License: MIT Imports: 6 Imported by: 0

README

Muxlist

Build Status

It's like a route debugger for Gorilla/Mux or your favorite router.

Coming from PHP, web frameworks i use usually have a command to view the registered routes. Since i am used to that, i decided to do something for gorrila/mux since i use it quite a bit.

Muxlist

Usage


    r := mux.NewRouter()

	r.Handle("/", index).Methods("GET")

	r.HandleFunc("/logout", logout).Methods("GET")

	r.Handle("/login", login).Methods("GET", "POST")

	r.Handle("/signup", signup).Methods("GET", "POST")

	r.Handle("/recipes/create", addRecipe).Methods("GET")

	muxlist.NewMuxLister(muxlist.NewGorillaMuxLister(r)).Table()

Naturally, you should only run this in development, so you'd have something like if development { ... }

The methods for the routes are currently not available since there is still a pending PR for that in gorrila/mux. But i'd get it in as soon as it gets merged in

This currently works for gorrila/mux but could be extended to work for any other multiplexer. All that is needed is a struct that satisfies Extractor.

Extractor looks like :


type Extractor interface {
	Extract() ResultSet
	List() string
}

Then register it with


muxlist.NewMuxLister(muxlist.NewLister())
muxlist.Table()


LICENSE

MIT

Documentation

Overview

Provides a Multiplexer lister for Gorilla/mux

Index

Constants

View Source
const (
	HTTP_METHODS = iota
	REQUEST_URI
	ROUTE_NAME
	HANDLER_NAME
)

Constants that map to a key in a Result. This is provided to be used as "helpers".

Variables

This section is empty.

Functions

func GetHumanReadableNameForHandler

func GetHumanReadableNameForHandler(h http.Handler) string

Returns a human readable name for a http Handler

Types

type Extractor

type Extractor interface {
	//This method is exported as the ResultSet might want to be inspected manually
	Extract() ResultSet
	List() string
}

type GorillaMuxLister

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

func NewGorillaMuxLister

func NewGorillaMuxLister(r *mux.Router) *GorillaMuxLister

Allocates and returns a new GorillaMuxLister

func (*GorillaMuxLister) Extract

func (m *GorillaMuxLister) Extract() ResultSet

func (*GorillaMuxLister) List

func (m *GorillaMuxLister) List() string

type MuxLister

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

func NewMuxLister

func NewMuxLister(e Extractor) *MuxLister

Allocates and returns a new Multiplexer lister

func (*MuxLister) Table

func (lister *MuxLister) Table()

Prints out a table containing data from a multiplexer This only works when in Development mode. In Production mode, this is a no-op

type Result

type Result map[int]string

Represents information for a single route

type ResultSet

type ResultSet []Result

ResultSet contains all available information for a multiplexer

Jump to

Keyboard shortcuts

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