忘れない内に記載しておく
まず、以下のプログラムを、web-server.go とかいう名前でセーブして、go build web-server.go をすると、 web-server という実行フィイルができる。
ところが、問題は、これを、任意のディレクトリから実行させようとすると、絶対パスの記載が必要となり、これを見つけるのに結構な時間がかかった。
結果としては、以下のようにすれば良いらしい(動いている)。
func main() {
// localhost:8080 でアクセスした時に index.html を読み込む
//http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// http.ServeFile(w, r, "index.html")
//})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "/home/pi/wstest33/index.html")
})
http.HandleFunc("/chat", HandleClients)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("error starting http server::", err)
return
}
}
上記のプログラムを、"http:/localhost:8080/xxxxx.html"とブラウザに打ちこむと
/home/pi/wstest33/index.htmlのファイルが表示される