ch3.2
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user