Releases: gossie/router
Releases · gossie/router
v1.0.0-beta.2
v1.0.0-beta.1
What's Changed
- Update README.md by @gossie in #6
- #5 apply middleware functions for single routes by @gossie in #7
- #9 transforms static route elements to lower case by @gossie in #10
- Feature/8 apply middleware functions for group of routes by @gossie in #11
- #12 reduces allocations by @gossie in #14
- Refactor/12 perform benchmark by @gossie in #15
Full Changelog: v0.2.0...v1.0.0-beta.1
v0.2.0
- Middleware function to support basic auth
import (
"net/http"
"github.com/gossie/router"
)
func main() {
userChecker := func(us *router.UserData) bool {
// TODO: check the UserData and return true if username and password matches, false otherwise
}
httpRouter := router.New()
httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Use(router.BasicAuth(userChecker))
log.Fatal(http.ListenAndServe(":8080", httpRouter))
}
- Middleware function to set headers for browser caching
import (
"net/http"
"github.com/gossie/router"
)
func main() {
httpRouter := router.New()
httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Use(router.Cache(1 * time.Hour))
log.Fatal(http.ListenAndServe(":8080", httpRouter))
}
v0.1.0
- Support custom middleware functions
import (
"net/http"
"github.com/gossie/router"
)
func logRequestTime(handler router.HttpHandler) router.HttpHandler {
return func(w http.ResponseWriter, r *http.Request, m map[string]string) {
start := time.Now()
defer func() {
log.Default().Println("request took", time.Since(start).Milliseconds(), "ms")
}()
handler(w, r, m)
}
}
func main() {
httpRouter := router.New()
httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Use(logRequestTime)
log.Fatal(http.ListenAndServe(":8080", httpRouter))
}