Created
February 12, 2016 23:19
-
-
Save guregu/8317af56ef26aed59773 to your computer and use it in GitHub Desktop.
Compsing kami
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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