From 5582bb6acdb63ee587f2df5db4a6e439821910b3 Mon Sep 17 00:00:00 2001 From: mikestefanello Date: Sat, 11 Dec 2021 19:32:34 -0500 Subject: [PATCH] Variable naming cleanup. --- config/config.go | 82 ++++++++++++++++++++------------------- controllers/controller.go | 7 ++-- controllers/page.go | 6 +-- controllers/register.go | 1 + msg/msg.go | 1 + 5 files changed, 51 insertions(+), 46 deletions(-) diff --git a/config/config.go b/config/config.go index 2a00cdd..393cbc4 100644 --- a/config/config.go +++ b/config/config.go @@ -23,48 +23,50 @@ const ( EnvProduction Env = "prod" ) -// Config stores complete application configuration -type Config struct { - HTTP HTTPConfig - App AppConfig - Cache CacheConfig - Database DatabaseConfig -} - -// HTTPConfig stores HTTP configuration -type HTTPConfig struct { - Hostname string `env:"HTTP_HOSTNAME"` - Port uint16 `env:"HTTP_PORT,default=8000"` - ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"` - WriteTimeout time.Duration `env:"HTTP_WRITE_TIMEOUT,default=10s"` - IdleTimeout time.Duration `env:"HTTP_IDLE_TIMEOUT,default=2m"` -} - -// AppConfig stores application configuration -type AppConfig struct { - Name string `env:"APP_NAME,default=Goweb"` - Environment Env `env:"APP_ENV,default=local"` - EncryptionKey string `env:"APP_ENCRYPTION_KEY,default=?E(G+KbPeShVmYq3t6w9z$C&F)J@McQf"` - Timeout time.Duration `env:"APP_TIMEOUT,default=20s"` -} - -type CacheConfig struct { - Hostname string `env:"CACHE_HOSTNAME,default=localhost"` - Port uint16 `env:"CACHE_PORT,default=6379"` - Password string `env:"CACHE_PASSWORD"` - Expiration struct { - StaticFile time.Duration `env:"CACHE_EXPIRATION_STATIC_FILE,default=4380h"` - Page time.Duration `env:"CACHE_EXPIRATION_PAGE,default=24h"` +type ( + // Config stores complete application configuration + Config struct { + HTTP HTTPConfig + App AppConfig + Cache CacheConfig + Database DatabaseConfig } -} -type DatabaseConfig struct { - Hostname string `env:"DB_HOSTNAME,default=localhost"` - Port uint16 `env:"DB_PORT,default=5432"` - User string `env:"DB_USER,default=admin"` - Password string `env:"DB_PASSWORD,default=admin"` - Database string `env:"DB_NAME,default=app"` -} + // HTTPConfig stores HTTP configuration + HTTPConfig struct { + Hostname string `env:"HTTP_HOSTNAME"` + Port uint16 `env:"HTTP_PORT,default=8000"` + ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"` + WriteTimeout time.Duration `env:"HTTP_WRITE_TIMEOUT,default=10s"` + IdleTimeout time.Duration `env:"HTTP_IDLE_TIMEOUT,default=2m"` + } + + // AppConfig stores application configuration + AppConfig struct { + Name string `env:"APP_NAME,default=Goweb"` + Environment Env `env:"APP_ENV,default=local"` + EncryptionKey string `env:"APP_ENCRYPTION_KEY,default=?E(G+KbPeShVmYq3t6w9z$C&F)J@McQf"` + Timeout time.Duration `env:"APP_TIMEOUT,default=20s"` + } + + CacheConfig struct { + Hostname string `env:"CACHE_HOSTNAME,default=localhost"` + Port uint16 `env:"CACHE_PORT,default=6379"` + Password string `env:"CACHE_PASSWORD"` + Expiration struct { + StaticFile time.Duration `env:"CACHE_EXPIRATION_STATIC_FILE,default=4380h"` + Page time.Duration `env:"CACHE_EXPIRATION_PAGE,default=24h"` + } + } + + DatabaseConfig struct { + Hostname string `env:"DB_HOSTNAME,default=localhost"` + Port uint16 `env:"DB_PORT,default=5432"` + User string `env:"DB_USER,default=admin"` + Password string `env:"DB_PASSWORD,default=admin"` + Database string `env:"DB_NAME,default=app"` + } +) // GetConfig loads and returns application configuration func GetConfig() (Config, error) { diff --git a/controllers/controller.go b/controllers/controller.go index 7f6db0a..36454b9 100644 --- a/controllers/controller.go +++ b/controllers/controller.go @@ -78,16 +78,17 @@ func (t *Controller) cachePage(c echo.Context, p Page, html *bytes.Buffer) { return } - if p.Cache.MaxAge == 0 { - p.Cache.MaxAge = t.Container.Config.Cache.Expiration.Page + if p.Cache.Expiration == 0 { + p.Cache.Expiration = t.Container.Config.Cache.Expiration.Page } key := c.Request().URL.String() opts := &store.Options{ - Expiration: p.Cache.MaxAge, + Expiration: p.Cache.Expiration, Tags: p.Cache.Tags, } cp := middleware.CachedPage{ + URL: key, HTML: html.Bytes(), Headers: p.Headers, StatusCode: p.StatusCode, diff --git a/controllers/page.go b/controllers/page.go index 5e10f3c..891542b 100644 --- a/controllers/page.go +++ b/controllers/page.go @@ -37,9 +37,9 @@ type Page struct { CSRF string Headers map[string]string Cache struct { - Enabled bool - MaxAge time.Duration - Tags []string + Enabled bool + Expiration time.Duration + Tags []string } RequestID string } diff --git a/controllers/register.go b/controllers/register.go index 7b972f4..4fc7a38 100644 --- a/controllers/register.go +++ b/controllers/register.go @@ -26,6 +26,7 @@ func (r *Register) Get(c echo.Context) error { p.Name = "register" p.Title = "Register" p.Data = r.form + return r.RenderPage(c, p) } diff --git a/msg/msg.go b/msg/msg.go index 3140680..0576aef 100644 --- a/msg/msg.go +++ b/msg/msg.go @@ -43,6 +43,7 @@ func Set(c echo.Context, typ Type, message string) { // Get gets flash messages from the cookie storage. func Get(c echo.Context, typ Type) []string { sess := getSession(c) + fm := sess.Flashes(string(typ)) // If we have some messages. if len(fm) > 0 {