Skip to content

Instantly share code, notes, and snippets.

@hogedigo
Last active August 29, 2015 13:57
Show Gist options
  • Save hogedigo/9365627 to your computer and use it in GitHub Desktop.
Save hogedigo/9365627 to your computer and use it in GitHub Desktop.
GAE/Goでmartini
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)
}
@hogedigo
Copy link
Author

hogedigo commented Mar 5, 2014

XSS入れてしまっていたのでcontent-typeをJSONにしてごまかしたw
handlerの関数にResponseWriter型変数追加すると勝手に渡してくれる(Dependency Injection)。便利。
他にも自作ComponentをDIしたりもできる

@sinmetal
Copy link

testってどないして書いたら良いんだろ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment