Skip to content

shopsmart/httprouterpersist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

httprouterpersist

httprouterpersist is a wrapper for httprouter that allows you to use httprouter with standard http.HandleFunc by providing an alternative method for persisting params.

A trivial example is:

package main

import (
	"fmt"
	"github.com/gorilla/context"
	"net/http"
	"log"

	router "github.com/shopsmart/httprouterpersist"
)

func Index(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "hello, %s!\n", context.Get(r, "name"))
}

func main() {
	r := router.New()
	r.Persist = router.ContextPersist

	r.GET("/", Index)
	r.GET("/hello/:name", Hello)

	log.Fatal(http.ListenAndServe(":8080", r))
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages