Slim is a fork of Goji, a minimalistic web framework that values composability and simplicity.
- Slim opted to implement its request context using "code.google.com/p/go.net/context" (see here for an introduction).
- Slim middlewares can also be written using the simpler form:
func(ctx context.Context, w http.ResponseWriter, r *http.Request, next web.Handler)
package main
import (
"fmt"
"net/http"
"code.google.com/p/go.net/context"
"github.com/vanackere/slim"
"github.com/vanackere/slim/web"
)
func hello(ctx context.Context, w http.ResponseWriter, r *http.Request) {
p := web.URLParams(ctx)
fmt.Fprintf(w, "Hello, %s!", p["name"])
}
func main() {
slim.Get("/hello/:name", hello)
slim.Serve()
}
Slim also includes a sample application in the example
folder which
was artificially constructed to show off all of Slim's features. Check it out!
- Fork of the excellent Goji framework
- Compatible with
net/http
- URL patterns (both Sinatra style
/foo/:bar
patterns and regular expressions, as well as custom patterns) - Reconfigurable middleware stack
- Context/environment object threaded through middleware and handlers
- Context is the one from "code.google.com/p/go.net/context" (see here for an introduction)
- Automatic support for Einhorn, systemd, and more
- Graceful shutdown, and zero-downtime graceful reload when combined with Einhorn.
See Goji's README for why Goji's - and therore Slim's ! - approach is good.