Documentation
¶
Overview ¶
Package route provides URL router allowing usage of regexp in URL paths.
package main
import (
"github.com/taironas/route"
"net/http"
"fmt"
)
func main() {
r := new(route.Router)
r.HandleFunc("/users", usersHandler)
r.HandleFunc("/users/:id", userHandler)
r.HandleFunc("/users/:id/friends/:username", friendHandler)
http.ListenAndServe(":8080", r)
}
func usersHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to users handler!")
}
func userHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to user handler, user id = %s!", route.Context.Get(r, "id"))
}
func friendHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to friend handler, friend username = %s!", route.Context.Get(r, "username"))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Context context
Context holds URL parameters indexed by HTTP request
Functions ¶
This section is empty.
Types ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router serves HTTP requests for added routes and static resources
func (*Router) AddStaticResource ¶
AddStaticResource adds a resource value to an array of static resources. Use this if you want to serve a static directory and it's sub directories.
func (*Router) HandleFunc ¶
HandleFunc registers the handler function for the given pattern in the router.
Click to show internal directories.
Click to hide internal directories.