chapter 3 done
parent
9cdbca7dc1
commit
5181aabd14
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func (app *application) serverError(w http.ResponseWriter, err error) {
|
||||
trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack())
|
||||
app.errorLog.Output(2, trace)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
func (app *application) clientError(w http.ResponseWriter, status int) {
|
||||
http.Error(w, http.StatusText(status), status)
|
||||
}
|
||||
|
||||
func (app *application) notFound(w http.ResponseWriter) {
|
||||
app.clientError(w, http.StatusNotFound)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
func (app *application) routes() *http.ServerMux {
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue