|
|
@ -11,13 +11,19 @@ func main() {
|
|
|
|
addr := flag.String("addr", ":4000", "HTTP network address")
|
|
|
|
addr := flag.String("addr", ":4000", "HTTP network address")
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
|
|
|
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/"))
|
|
|
|
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
|
|
|
|
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
|
|
|
|
mux.HandleFunc("/", home)
|
|
|
|
mux.HandleFunc("/", home)
|
|
|
|
mux.HandleFunc("/snippet/view", snippetView)
|
|
|
|
mux.HandleFunc("/snippet/view", snippetView)
|
|
|
|
mux.HandleFunc("/snippet/create", snippetCreate)
|
|
|
|
mux.HandleFunc("/snippet/create", snippetCreate)
|
|
|
|
log.Printf("Starting server on %s", *addr)
|
|
|
|
srv := &http.Server{
|
|
|
|
err := http.ListenAndServe(*addr, mux)
|
|
|
|
Addr: *addr,
|
|
|
|
log.Fatal(err)
|
|
|
|
ErrorLog: errorLog,
|
|
|
|
|
|
|
|
Handler: mux,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
infoLog.Printf("Starting server on %s", *addr)
|
|
|
|
|
|
|
|
err := srv.ListenAndServe()
|
|
|
|
|
|
|
|
errorLog.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|