package main
import (
_ "embed"
"net/http"
"os"
)
//go:embed index.html
var index []byte
//go:embed 432.mp3
var tone432 []byte
//go:embed favicon.ico
var favicon []byte
const (
etag432 = "1"
etagFavicon = "1"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
w.WriteHeader(http.StatusNotFound)
return
}
w.Write(index)
})
http.HandleFunc("/432.mp3", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("If-None-Match") == etag432 {
w.WriteHeader(http.StatusNotModified)
return
}
w.Header().Add("ETag", etag432)
w.Write(tone432)
})
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("If-None-Match") == etagFavicon {
w.WriteHeader(http.StatusNotModified)
return
}
w.Header().Add("ETag", etagFavicon)
w.Write(favicon)
})
http.ListenAndServe(":"+os.Args[1], nil)
}