mirror of
https://github.com/ariejan/i6502.git
synced 2025-04-21 12:39:47 +00:00
41 lines
699 B
Go
41 lines
699 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
"text/template"
|
|
)
|
|
|
|
var (
|
|
addr = flag.String("addr", ":6123", "http service address")
|
|
homeTmpl = template.Must(template.ParseFiles("home.html"))
|
|
)
|
|
|
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.Error(w, "Not found", 404)
|
|
return
|
|
}
|
|
|
|
if r.Method != "GET" {
|
|
http.Error(w, "Method not allowed", 405)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
homeTmpl.Execute(w, r.Host)
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
http.HandleFunc("/", serveHome)
|
|
http.HandleFunc("/ws", serveWs)
|
|
|
|
err := http.ListenAndServe(*addr, nil)
|
|
if err != nil {
|
|
log.Fatal("ListenAndServe: ", err)
|
|
}
|
|
}
|