Help us shape the future of Go! Take the 2026 Go Developer Survey

route

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: LGPL-3.0 Imports: 9 Imported by: 4

README

Route

Go Report Card

Simple router for web application.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitPath

func SplitPath(path string) []string

SplitPath is an utils function that will split the path of a request.

Types

type DynamicRouter

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

DynamicRouter is a simple http router

Implements the http/Handler interface

func NewDynamicRouter

func NewDynamicRouter() *DynamicRouter

NewDynamicRouter create a new DynamicRouter

func (*DynamicRouter) HandleFunc

func (r *DynamicRouter) HandleFunc(pattern string, handler Handler, filters ...HttpFilter)

HandleFunc register a new Handler for a given pattern

func (*DynamicRouter) ServeHTTP

func (r *DynamicRouter) ServeHTTP(res http.ResponseWriter, req *http.Request)

http/Handler implementation

func (*DynamicRouter) ServeStaticAt

func (r *DynamicRouter) ServeStaticAt(root string, mode FileServerMode)

type FileServerMode

type FileServerMode string

FileServerMode allow to adapt some behavior of the file server.

const (
	// classic mode handle all requests considering that there is no routing in front end code.
	// it behave like "classic" web app. When a resource is not found => 404
	Classic FileServerMode = "classic"
	// spa mode considers that all the routing is done in the browser. Some files other than index.html
	// may be loaded, but if a request does not fit a file, the request is changed to serve `/` instead.
	Spa FileServerMode = "spa"
)

type Handler

type Handler func(context.Context, http.ResponseWriter, *http.Request)

function type used by application code

func WrapHttpHandleFunc

func WrapHttpHandleFunc(f func(w http.ResponseWriter, r *http.Request)) Handler

WrapHttpHandleFunc make easier to integrate route with existing code by transforming a standart httpHandleFunc into a route.Handler

type HttpFilter

type HttpFilter func(http.ResponseWriter, *http.Request) bool

functions that are executed before there corresponding handler. if an error is returned, the pipe execution is stopped. The filter MUST take care of status and body response.

Jump to

Keyboard shortcuts

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