A simple way to handle form submissions from static websites.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
1.1 KiB

package main
import (
"errors"
"github.com/caarlos0/env/v6"
)
type config struct {
Port int `env:"PORT" envDefault:"8080"`
HoneyPots []string `env:"HONEYPOTS" envDefault:"_t_email" envSeparator:","`
DefaultRecipient string `env:"DEFAULT_TO"`
AllowedRecipients []string `env:"ALLOWED_TO" envSeparator:","`
Sender string `env:"EMAIL_FROM"`
SmtpUser string `env:"SMTP_USER"`
SmtpPassword string `env:"SMTP_PASS"`
SmtpHost string `env:"SMTP_HOST"`
SmtpPort int `env:"SMTP_PORT" envDefault:"587"`
}
func parseConfig() (config, error) {
cfg := config{}
if err := env.Parse(&cfg); err != nil {
return cfg, errors.New("failed to parse config")
}
return cfg, nil
}
func checkRequiredConfig(cfg config) bool {
if cfg.DefaultRecipient == "" {
return false
}
if len(cfg.AllowedRecipients) < 1 {
return false
}
if cfg.Sender == "" {
return false
}
if cfg.SmtpUser == "" {
return false
}
if cfg.SmtpPassword == "" {
return false
}
if cfg.SmtpHost == "" {
return false
}
return true
}