ch3.5
This commit is contained in:
@@ -31,18 +31,10 @@ func main() {
|
|||||||
infoLog: infoLog,
|
infoLog: infoLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
|
||||||
|
|
||||||
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{
|
srv := &http.Server{
|
||||||
Addr: cfg.addr,
|
Addr: cfg.addr,
|
||||||
ErrorLog: errorLog,
|
ErrorLog: errorLog,
|
||||||
Handler: mux,
|
Handler: app.routes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
infoLog.Printf("Starting server on %s", cfg.addr)
|
infoLog.Printf("Starting server on %s", cfg.addr)
|
||||||
|
|||||||
16
cmd/web/routes.go
Normal file
16
cmd/web/routes.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func (app *application) routes() *http.ServeMux {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
||||||
|
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
|
||||||
|
|
||||||
|
mux.HandleFunc("/", app.home)
|
||||||
|
mux.HandleFunc("/snippet/view", app.snippetView)
|
||||||
|
mux.HandleFunc("/snippet/create", app.snippetCreate)
|
||||||
|
|
||||||
|
return mux
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user