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,48 +23,50 @@ const (
EnvProduction Env = "prod" EnvProduction Env = "prod"
) )
// Config stores complete application configuration type (
type Config struct { // Config stores complete application configuration
HTTP HTTPConfig Config struct {
App AppConfig HTTP HTTPConfig
Cache CacheConfig App AppConfig
Database DatabaseConfig 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 DatabaseConfig struct { // HTTPConfig stores HTTP configuration
Hostname string `env:"DB_HOSTNAME,default=localhost"` HTTPConfig struct {
Port uint16 `env:"DB_PORT,default=5432"` Hostname string `env:"HTTP_HOSTNAME"`
User string `env:"DB_USER,default=admin"` Port uint16 `env:"HTTP_PORT,default=8000"`
Password string `env:"DB_PASSWORD,default=admin"` ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"`
Database string `env:"DB_NAME,default=app"` 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 // 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

@ -37,9 +37,9 @@ type Page struct {
CSRF string CSRF string
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 {