This commit is contained in:
lbenedar
2026-03-04 15:01:26 +03:00
parent d291ceb5fd
commit 9085959978
2 changed files with 19 additions and 10 deletions

View File

@@ -7,6 +7,11 @@ import (
"os"
)
type application struct {
errorLog *log.Logger
infoLog *log.Logger
}
type config struct {
addr string
staticDir string
@@ -18,15 +23,20 @@ func main() {
flag.StringVar(&cfg.staticDir, "static-dir", "./ui/static", "Path to static assets")
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)
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
app := &application{
errorLog: errorLog,
infoLog: infoLog,
}
mux := http.NewServeMux()
fileServer := http.FileServer(http.Dir("./ui/static/"))
mux.HandleFunc("/", home)
mux.HandleFunc("/snippet/view", snippetView)
mux.HandleFunc("/snippet/create", snippetCreate)
mux.HandleFunc("/", app.home)
mux.HandleFunc("/snippet/view", app.snippetView)
mux.HandleFunc("/snippet/create", app.snippetCreate)
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
srv := &http.Server{