ch3.1
This commit is contained in:
@@ -1,11 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
addr string
|
||||||
|
staticDir string
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var cfg config
|
||||||
|
flag.StringVar(&cfg.addr, "addr", ":4000", "HTTP network address")
|
||||||
|
flag.StringVar(&cfg.staticDir, "static-dir", "./ui/static", "Path to static assets")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
||||||
|
|
||||||
@@ -14,7 +25,7 @@ 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.Print("Starting server on :4000")
|
log.Printf("Starting server on %s", cfg.addr)
|
||||||
err := http.ListenAndServe(":4000", mux)
|
err := http.ListenAndServe(cfg.addr, mux)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user