Slide 19
Slide 19 text
hello.go (GAE/G&HTTPサーバー)
package hello
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, 世界!")
}
1.package名をhelloからmainに変更
2.関数名のinit()をmain()に書き換え
3.main()関数の最後に以下の一行を追記
http.ListenAndServe(“:8080”, nil)
これで、HTTPサーバーに早変わり!