Browse Source

Export App struct

main
Matt Baer 3 years ago
parent
commit
b1551ce9f5
4 changed files with 8 additions and 8 deletions
  1. +3
    -3
      app.go
  2. +2
    -2
      handler.go
  3. +2
    -2
      routes.go
  4. +1
    -1
      templates.go

+ 3
- 3
app.go View File

@@ -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,
}



+ 2
- 2
handler.go View File

@@ -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)


+ 2
- 2
routes.go View File

@@ -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"]



+ 1
- 1
templates.go View File

@@ -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)


Loading…
Cancel
Save