Created
September 22, 2013 00:04
-
-
Save gongo/6655410 to your computer and use it in GitHub Desktop.
https://github.com/golang-samples/goweb/blob/master/mapfunc/main.go がそのままだと動かなかったので、とりあえず動く感じにしてみた
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" | |
"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