Example #1
0
File: main.go Project: haochi/koala
func main() {
	app := koala.New()

	app.AddRouteHandler("GET", "/static/{path}", http.StripPrefix("/static/", http.FileServer(http.Dir("/tmp"))))

	panic(http.ListenAndServe(":8080", app))
}
Example #2
0
File: main.go Project: haochi/koala
func main() {
	app := koala.New()
	app2 := koala.New()

	app.Get("/~{id}", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Fprintf(writer, "user %s reporting for duty!", koala.Param(request, "id"))
	})

	app.Get("/~{id}/hello", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Fprintf(writer, "hello %s!", koala.Param(request, "id"))
	})

	app2.Get("/", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Fprint(writer, "serving the second app at a different port: ", request.Host)
	})

	ListenAndServe(map[*koala.Mux]string{
		app:  ":8080",
		app2: ":8081",
	})
}
Example #3
0
File: main.go Project: haochi/koala
func main() {
	app := koala.New()

	app.Get("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, World!")
	})

	app.Get("/~{id}", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "user %s reporting for duty!", koala.Param(r, "id"))
	})

	panic(http.ListenAndServe(":8080", app))
}