Skip to content

Instantly share code, notes, and snippets.

@gongo
Created September 22, 2013 00:04
Show Gist options
  • Save gongo/6655410 to your computer and use it in GitHub Desktop.
Save gongo/6655410 to your computer and use it in GitHub Desktop.
https://github.com/golang-samples/goweb/blob/master/mapfunc/main.go がそのままだと動かなかったので、とりあえず動く感じにしてみた
package main
import (
"fmt"
"github.com/stretchr/goweb"
"github.com/stretchr/goweb/context"
"net/http"
)
func main() {
goweb.Map("/", func(c context.Context) error {
return goweb.Respond.With(c, 200, []byte("Hello, World!"))
})
goweb.Map("/{name}/animals/{animal}", func(c context.Context) error {
name := c.PathParams().Get("name")
animal := c.PathParams().Get("animal")
return goweb.Respond.With(c, 200, []byte(fmt.Sprintf("Hey %s, your favorite animal is a %s", name, animal)))
})
http.ListenAndServe(":8080", goweb.DefaultHttpHandler())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment