multiplexer

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Vars added in v0.1.7

func Vars(r *http.Request) map[string]string

Types

type Router

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

Router struct is router that will help to routing every incoming request. This router used tree data structure to do request routin

func NewRouter

func NewRouter(basepath string) *Router

NewRouter will return *Router.

func (*Router) Handle

func (rt *Router) Handle(path string, handler http.Handler)

Handle function is used to add handler in specific path to the router. This function take two parameters. the first parameter is path with type of string and the second paramater is handler which is a http.Handler The path that will be inserted to the router can have paremeter. To do that, the path should be written like this example : -- /home/user/{id:int} --> id is a parameter in path that just accept numeric value -- /home/{slug_name:slug} --> slug_name is a parameter in path that just accept slug You can use int, float, slug, and string in parameters Every parameter will return a string value

func (*Router) HandleFunc

func (rt *Router) HandleFunc(path string, handlerFunc http.HandlerFunc)

HandleFunc function is used to add handlerfunction in specific path to the router. This function take two parameters. the first parameter is path with type of string and the second paramater is a http.handlerFunc The path that will be inserted to the router, can have paremeter. To do that, the path should be written like this example : -- /home/user/{id:int} --> id is a parameter in path that just accept numeric value -- /home/{slug_name:slug} --> slug_name is a parameter in path that just accept slug You can use int, float, slug, and string in parameters Every parameter will return a string value

func (*Router) Methods

func (rt *Router) Methods(methods ...string) *Router

Set every http method that will assign to the path that will be added into Router object

func (*Router) Query

func (rt *Router) Query(r *http.Request, key string) string

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) SetPrefix

func (rt *Router) SetPrefix(prefix string) *Router

SetPrefix will set prefix for Router object. Every path will be start with prefix to access it example : the original path --> /id with prefix = "product" => product/id

func (*Router) SubRouter

func (rt *Router) SubRouter(router *Router) error

Function SubRouter will add sub router to main router

Jump to

Keyboard shortcuts

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