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"
)
// 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) {

View File

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

View File

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

View File

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

View File

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