This commit is contained in:
lbenedar
2026-03-04 14:04:07 +03:00
parent cfc4aa38cd
commit d291ceb5fd

View File

@@ -4,6 +4,7 @@ import (
"flag" "flag"
"log" "log"
"net/http" "net/http"
"os"
) )
type config struct { type config struct {
@@ -17,6 +18,9 @@ func main() {
flag.StringVar(&cfg.staticDir, "static-dir", "./ui/static", "Path to static assets") flag.StringVar(&cfg.staticDir, "static-dir", "./ui/static", "Path to static assets")
flag.Parse() flag.Parse()
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
mux := http.NewServeMux() mux := http.NewServeMux()
fileServer := http.FileServer(http.Dir("./ui/static/")) fileServer := http.FileServer(http.Dir("./ui/static/"))
@@ -25,7 +29,13 @@ func main() {
mux.HandleFunc("/snippet/create", snippetCreate) mux.HandleFunc("/snippet/create", snippetCreate)
mux.Handle("/static/", http.StripPrefix("/static", fileServer)) mux.Handle("/static/", http.StripPrefix("/static", fileServer))
log.Printf("Starting server on %s", cfg.addr) srv := &http.Server{
err := http.ListenAndServe(cfg.addr, mux) Addr: cfg.addr,
log.Fatal(err) ErrorLog: errorLog,
Handler: mux,
}
infoLog.Printf("Starting server on %s", cfg.addr)
err := srv.ListenAndServe()
errorLog.Fatal(err)
} }