diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2026-01-21 00:40:17 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2026-01-21 00:40:17 -0500 |
| commit | cbb0dafad526128d10ff5f4859a1990132e4f75e (patch) | |
| tree | 97f538f1797a3ff82088d9875b5fcce92b5e812a /cmd | |
| parent | c5b07cd82fde44730997068029371f453bf31771 (diff) | |
| download | go-website-wip.tar.gz go-website-wip.tar.xz | |
Clean up the example site a touch and make a quick pass on the config load errorswip
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/server/app.go | 42 | ||||
| -rw-r--r-- | cmd/server/handlers.go | 3 | ||||
| -rw-r--r-- | cmd/server/main.go | 13 |
3 files changed, 27 insertions, 31 deletions
diff --git a/cmd/server/app.go b/cmd/server/app.go index c694753..a8d1ce8 100644 --- a/cmd/server/app.go +++ b/cmd/server/app.go @@ -39,25 +39,7 @@ type App struct { FeedPrefix string } -func newApp() *App { - return &App{} -} - -func loadConf(fn string) (*App, error) { - fh, err := os.Open(fn) - if err != nil { - return nil, fmt.Errorf("loading config: %w", err) - } - - dec := yaml.NewDecoder(fh) - - app := newApp() - - err = dec.Decode(app) - if err != nil { - return nil, fmt.Errorf("decoding yaml: %w", err) - } - +func (app *App) setDefaults() { if app.StaticDirectory == "" { app.StaticDirectory = "static" } @@ -85,8 +67,28 @@ func loadConf(fn string) (*App, error) { page.Global = map[string]interface{}{ "App": app, } +} + +func loadConf(fn string) (*App, error) { + var dec *yaml.Decoder + app := &App{} + + fh, err := os.Open(fn) + if err != nil { + err = fmt.Errorf("loading config: %w", err) + goto loadConfRet + } + + dec = yaml.NewDecoder(fh) + + err = dec.Decode(app) + if err != nil { + err = fmt.Errorf("decoding yaml: %w", err) + } - return app, nil +loadConfRet: + app.setDefaults() + return app, err } func (a *App) ClearCache() error { diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go index e6d2203..49f2039 100644 --- a/cmd/server/handlers.go +++ b/cmd/server/handlers.go @@ -4,6 +4,7 @@ import ( "net/http" "path/filepath" "strings" + "fmt" "riedstra.dev/mitch/go-website/mapcache" "riedstra.dev/mitch/go-website/page" @@ -55,6 +56,8 @@ func (a *App) Handler() http.Handler { } for _, r := range cacheableRoutes { + fmt.Printf("Calling mux.Handle(r.path(%s), cacheHandler(r.handler(%v)))\n", + r.path, r.handler) mux.Handle(r.path, cacheHandler(r.handler)) } diff --git a/cmd/server/main.go b/cmd/server/main.go index a776980..1b59bbe 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -36,7 +36,6 @@ func main() { //nolint:funlen directory = "." version = false confFn = "conf.yml" - authConfFn = "auth.json" verbose = false defaultIndexPath = "/reIndex" indexPath = "/reIndex" @@ -56,8 +55,6 @@ func main() { //nolint:funlen "print version and exit")) envflag.String(fl, &confFn, "c", "CONFIG_FILE", "Location for configuration file") - envflag.String(fl, &authConfFn, "ac", "AUTH_CONFIG", - "location for the authorization config") logIfErr(envflag.Bool(fl, &verbose, "V", "VERBOSE", "Be more verbose, dump config and such")) envflag.String(fl, &page.TimeFormat, "T", "TIME_FORMAT", @@ -94,20 +91,14 @@ func main() { //nolint:funlen app, err := loadConf(confFn) if err != nil { - logger.Println(err) - - app = &App{} + logger.Print(err) + logger.Fatal("A configuration file must be supplied. No valid config read") } if mapcache { app.mapCache = true } - err = app.ReadAuth(authConfFn) - if err != nil { - logger.Println(err) - } - if app.ReIndexPath == "" || indexPath != defaultIndexPath { app.ReIndexPath = indexPath } |
