daryl / Zeus
Licence: mit
Go HTTP router.
Stars: ✭ 109
Programming Languages
go
31211 projects - #10 most used programming language
Zeus
Zeus is a super-duper, simple and fast HTTP router for Go, nothing more, nothing less.
Install
go get github.com/daryl/zeus
Usage
package main
import (
"fmt"
"github.com/daryl/zeus"
"net/http"
)
func main() {
mux := zeus.New()
// Supports named parameters.
mux.GET("/users/:id", showUser)
// Supports wildcards anywhere.
mux.GET("/foo/*", catchFoo)
// Custom 404 handler.
mux.NotFound = notFound
// Listen and serve.
mux.Listen(":4545")
}
func showUser(w http.ResponseWriter, r *http.Request) {
var id string
// Get a map of all
// route variables.
vm := zeus.Vars(r)
id = vm["id"]
// Or just one.
id = zeus.Var(r, "id")
fmt.Fprintf(w, "User ID: %s", id)
}
func catchFoo(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Gotta catch 'em all"))
}
func notFound(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Nothing to see here"))
}
Documentation
For further documentation, check out GoDoc.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].