From b1551ce9f51330abe467e77008a4fc49a071b073 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 30 Mar 2021 22:24:40 -0400 Subject: [PATCH] Export App struct --- app.go | 6 +++--- handler.go | 4 ++-- routes.go | 4 ++-- templates.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app.go b/app.go index 32e58bb..629dee0 100644 --- a/app.go +++ b/app.go @@ -22,14 +22,14 @@ var ( softwareVer = "0.1.0" ) -type app struct { +type App struct { router *mux.Router cfg *Config singleUser *Profile } -func (app *app) multiUser() bool { +func (app *App) multiUser() bool { return app.singleUser == nil } @@ -42,7 +42,7 @@ type Config struct { } func Serve(cfg *Config) { - app := &app{ + app := &App{ cfg: cfg, } diff --git a/handler.go b/handler.go index 347be81..fc4075a 100644 --- a/handler.go +++ b/handler.go @@ -6,9 +6,9 @@ import ( "net/http" ) -type handlerFunc func(app *app, w http.ResponseWriter, r *http.Request) error +type handlerFunc func(app *App, w http.ResponseWriter, r *http.Request) error -func (app *app) handler(h handlerFunc) http.HandlerFunc { +func (app *App) handler(h handlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { handleError(w, r, func() error { return h(app, w, r) diff --git a/routes.go b/routes.go index 7d2e3d1..48559b1 100644 --- a/routes.go +++ b/routes.go @@ -5,14 +5,14 @@ import ( "net/http" ) -func initRoutes(app *app) { +func initRoutes(app *App) { app.router = mux.NewRouter() app.router.HandleFunc("/", app.handler(handleViewProfile)) app.router.PathPrefix("/").Handler(http.FileServer(http.Dir("../../static/"))) } -func handleViewProfile(app *app, w http.ResponseWriter, r *http.Request) error { +func handleViewProfile(app *App, w http.ResponseWriter, r *http.Request) error { vars := mux.Vars(r) username := vars["username"] diff --git a/templates.go b/templates.go index 20c281d..f51bd2c 100644 --- a/templates.go +++ b/templates.go @@ -30,7 +30,7 @@ func renderTemplate(w io.Writer, tmpl string, data interface{}) error { return err } -func (app *app) pageHandler(name string) http.HandlerFunc { +func (app *App) pageHandler(name string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { handleError(w, r, func() error { return renderTemplate(w, name, nil)