diff options
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 30 |
1 files changed, 12 insertions, 18 deletions
@@ -9,8 +9,6 @@ import ( "xengineering.eu/ceres/controller" "xengineering.eu/ceres/model" "xengineering.eu/ceres/view" - - "github.com/gorilla/mux" ) type Server http.Server @@ -19,31 +17,27 @@ type Server http.Server var static embed.FS func NewServer(addr string, db *model.DB) *Server { - var r *mux.Router = mux.NewRouter() - - r.PathPrefix("/static/"). - Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static)))) + mux := http.NewServeMux() - r.HandleFunc("/version", view.VersionRead(version)).Methods(`GET`) + mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(static)))) - r.HandleFunc("/recipes", view.RecipesRead(db)).Methods(`GET`) - r.HandleFunc("/recipe/create", view.RecipeCreate).Methods(`GET`) + mux.HandleFunc("GET /version", view.VersionRead(version)) - r.HandleFunc("/recipe", controller.RecipeCreate(db)).Methods(`POST`) - r.HandleFunc("/recipe/{id:[0-9]+}", view.RecipeRead(db)).Methods(`GET`) - r.HandleFunc("/recipe/{id:[0-9]+}", controller.RecipeUpdate(db)).Methods(`POST`) - r.HandleFunc("/recipe/{id:[0-9]+}", controller.RecipeDelete(db)).Methods(`DELETE`) + mux.HandleFunc("GET /recipes", view.RecipesRead(db)) - r.HandleFunc("/favicon.ico", view.FaviconRead).Methods(`GET`) + mux.HandleFunc("GET /recipe/create", view.RecipeCreate) + mux.HandleFunc("POST /recipe", controller.RecipeCreate(db)) + mux.HandleFunc("GET /recipe/{id}", view.RecipeRead(db)) + mux.HandleFunc("POST /recipe/{id}", controller.RecipeUpdate(db)) + mux.HandleFunc("DELETE /recipe/{id}", controller.RecipeDelete(db)) - r.HandleFunc("/", view.IndexRead).Methods(`GET`) + mux.HandleFunc("GET /favicon.ico", view.FaviconRead) - muxer := http.NewServeMux() - muxer.Handle("/", r) + mux.HandleFunc("GET /", view.IndexRead) var srv http.Server srv.Addr = addr - srv.Handler = muxer + srv.Handler = mux log.Printf("Configured server to listen on http://%s\n", srv.Addr) |