Skip to content

Instantly share code, notes, and snippets.

@guregu
Created February 12, 2016 23:19
Show Gist options
  • Save guregu/8317af56ef26aed59773 to your computer and use it in GitHub Desktop.
Save guregu/8317af56ef26aed59773 to your computer and use it in GitHub Desktop.
Compsing kami
package main
import (
"fmt"
"net/http"
"github.com/guregu/kami"
"golang.org/x/net/context"
)
func index(_ context.Context, w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello world.")
}
func main() {
kami.Get("/", index)
http.Handle("/admin/", http.StripPrefix("/admin", adminMux()))
kami.Serve() // kami.Serve uses http.DefaultServeMux too
// alternative to the above 2 lines, manually serve
// http.Handle("/", kami.Handler())
// http.Handle("/admin/", http.StripPrefix("/admin", adminMux()))
// http.ListenAndServe(":8000", nil)
}
func adminMux() *kami.Mux {
mux := kami.New()
mux.Get("/memstats", memstats)
return mux
}
func memstats(_ context.Context, w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Admin page")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment