Last active
August 29, 2015 13:57
-
-
Save hogedigo/9365627 to your computer and use it in GitHub Desktop.
GAE/Goでmartini
This file contains 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 hello | |
import ( | |
"github.com/codegangsta/martini" | |
"net/http" | |
) | |
func init() { | |
m := martini.Classic() | |
m.Get("/hello/:name", func(params martini.Params, w http.ResponseWriter) string { | |
w.Header().Set("Content-Type", "application/json") | |
return "Hello! " + params["name"] | |
}) | |
http.Handle("/", m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
XSS入れてしまっていたのでcontent-typeをJSONにしてごまかしたw
handlerの関数にResponseWriter型変数追加すると勝手に渡してくれる(Dependency Injection)。便利。
他にも自作ComponentをDIしたりもできる