Variable naming cleanup.

This commit is contained in:
mikestefanello 2021-12-11 19:32:34 -05:00
parent bbf27d1b04
commit 5582bb6acd
5 changed files with 51 additions and 46 deletions

View file

@ -23,8 +23,9 @@ const (
EnvProduction Env = "prod" EnvProduction Env = "prod"
) )
type (
// Config stores complete application configuration // Config stores complete application configuration
type Config struct { Config struct {
HTTP HTTPConfig HTTP HTTPConfig
App AppConfig App AppConfig
Cache CacheConfig Cache CacheConfig
@ -32,7 +33,7 @@ type Config struct {
} }
// HTTPConfig stores HTTP configuration // HTTPConfig stores HTTP configuration
type HTTPConfig struct { HTTPConfig struct {
Hostname string `env:"HTTP_HOSTNAME"` Hostname string `env:"HTTP_HOSTNAME"`
Port uint16 `env:"HTTP_PORT,default=8000"` Port uint16 `env:"HTTP_PORT,default=8000"`
ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"` ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"`
@ -41,14 +42,14 @@ type HTTPConfig struct {
} }
// AppConfig stores application configuration // AppConfig stores application configuration
type AppConfig struct { AppConfig struct {
Name string `env:"APP_NAME,default=Goweb"` Name string `env:"APP_NAME,default=Goweb"`
Environment Env `env:"APP_ENV,default=local"` Environment Env `env:"APP_ENV,default=local"`
EncryptionKey string `env:"APP_ENCRYPTION_KEY,default=?E(G+KbPeShVmYq3t6w9z$C&F)J@McQf"` EncryptionKey string `env:"APP_ENCRYPTION_KEY,default=?E(G+KbPeShVmYq3t6w9z$C&F)J@McQf"`
Timeout time.Duration `env:"APP_TIMEOUT,default=20s"` Timeout time.Duration `env:"APP_TIMEOUT,default=20s"`
} }
type CacheConfig struct { CacheConfig struct {
Hostname string `env:"CACHE_HOSTNAME,default=localhost"` Hostname string `env:"CACHE_HOSTNAME,default=localhost"`
Port uint16 `env:"CACHE_PORT,default=6379"` Port uint16 `env:"CACHE_PORT,default=6379"`
Password string `env:"CACHE_PASSWORD"` Password string `env:"CACHE_PASSWORD"`
@ -58,13 +59,14 @@ type CacheConfig struct {
} }
} }
type DatabaseConfig struct { DatabaseConfig struct {
Hostname string `env:"DB_HOSTNAME,default=localhost"` Hostname string `env:"DB_HOSTNAME,default=localhost"`
Port uint16 `env:"DB_PORT,default=5432"` Port uint16 `env:"DB_PORT,default=5432"`
User string `env:"DB_USER,default=admin"` User string `env:"DB_USER,default=admin"`
Password string `env:"DB_PASSWORD,default=admin"` Password string `env:"DB_PASSWORD,default=admin"`
Database string `env:"DB_NAME,default=app"` Database string `env:"DB_NAME,default=app"`
} }
)
// GetConfig loads and returns application configuration // GetConfig loads and returns application configuration
func GetConfig() (Config, error) { func GetConfig() (Config, error) {

View file

@ -78,16 +78,17 @@ func (t *Controller) cachePage(c echo.Context, p Page, html *bytes.Buffer) {
return return
} }
if p.Cache.MaxAge == 0 { if p.Cache.Expiration == 0 {
p.Cache.MaxAge = t.Container.Config.Cache.Expiration.Page p.Cache.Expiration = t.Container.Config.Cache.Expiration.Page
} }
key := c.Request().URL.String() key := c.Request().URL.String()
opts := &store.Options{ opts := &store.Options{
Expiration: p.Cache.MaxAge, Expiration: p.Cache.Expiration,
Tags: p.Cache.Tags, Tags: p.Cache.Tags,
} }
cp := middleware.CachedPage{ cp := middleware.CachedPage{
URL: key,
HTML: html.Bytes(), HTML: html.Bytes(),
Headers: p.Headers, Headers: p.Headers,
StatusCode: p.StatusCode, StatusCode: p.StatusCode,

View file

@ -38,7 +38,7 @@ type Page struct {
Headers map[string]string Headers map[string]string
Cache struct { Cache struct {
Enabled bool Enabled bool
MaxAge time.Duration Expiration time.Duration
Tags []string Tags []string
} }
RequestID string RequestID string

View file

@ -26,6 +26,7 @@ func (r *Register) Get(c echo.Context) error {
p.Name = "register" p.Name = "register"
p.Title = "Register" p.Title = "Register"
p.Data = r.form p.Data = r.form
return r.RenderPage(c, p) return r.RenderPage(c, p)
} }

View file

@ -43,6 +43,7 @@ func Set(c echo.Context, typ Type, message string) {
// Get gets flash messages from the cookie storage. // Get gets flash messages from the cookie storage.
func Get(c echo.Context, typ Type) []string { func Get(c echo.Context, typ Type) []string {
sess := getSession(c) sess := getSession(c)
fm := sess.Flashes(string(typ)) fm := sess.Flashes(string(typ))
// If we have some messages. // If we have some messages.
if len(fm) > 0 { if len(fm) > 0 {