Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created February 19, 2015 18:51
Show Gist options
  • Save keizo042/c469fc1b016568ba6946 to your computer and use it in GitHub Desktop.
Save keizo042/c469fc1b016568ba6946 to your computer and use it in GitHub Desktop.
てきとーなWebapp
package main
/*
git clone して
go build webapp.go
./webapp
としたあと
http://localhost:8080
にアクセス
*/
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/",handleIndex)
http.HandleFunc("/ans",handleAns)
http.HandleFunc("/ans2",handleAns2)
http.ListenAndServe(":8080",nil)
}
func handleIndex(r http.ResponseWriter, req *http.Request) {
index := `
<html>
<body>
<h1> プログラミングは好きですか? </h1>
<a href="/ans">はい</a>
<br>
<a href="/ans2">いいえ</a>
</body>
</html>
`
fmt.Fprintln(r,index)
}
func handleAns(r http.ResponseWriter, req *http.Request) {
index := `
<html>
<body>
<h1> イイネッ </h1>
</body>
</html>
`
fmt.Fprintln(r,index)
}
func handleAns2(r http.ResponseWriter, req *http.Request) {
index := `
<html>
<body>
<h1> BBBOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO </h1>
</body>
</html>
`
fmt.Fprintln(r,index)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment