homepage/main.go

44 lines
741 B
Go

package main
import (
"embed"
"io/fs"
"log"
"net/http"
"time"
)
var version = "development"
//go:embed public/*
var embeddedPublic embed.FS
func main() {
// TODO: ENV WHATPORT
// TODO: handler for / + 404
root, err := fs.Sub(embeddedPublic, "public")
if err != nil {
log.Fatal(err)
}
fs := http.FileServer(http.FS(root))
http.Handle("/", fs)
log.Printf("app built from revision '%s'\n", version)
log.Print("Listening on :1314...")
// https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
srv := http.Server{
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
Addr: ":1314",
Handler: nil,
}
err = srv.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}