2024-02-26 12:30:53 +00:00
|
|
|
package config
|
|
|
|
|
2024-03-15 11:39:43 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2024-02-28 13:47:33 +00:00
|
|
|
|
|
|
|
var _ Validator = (*MailConfig)(nil)
|
2024-03-15 11:39:43 +00:00
|
|
|
var _ Defaults = (*MailConfig)(nil)
|
2024-02-28 13:47:33 +00:00
|
|
|
|
2024-02-26 12:30:53 +00:00
|
|
|
type MailConfig struct {
|
2024-03-15 11:39:18 +00:00
|
|
|
Host string `mapstructure:"host"`
|
|
|
|
Port int `mapstructure:"port"`
|
|
|
|
SSL bool `mapstructure:"ssl"`
|
|
|
|
AuthType string `mapstructure:"auth_type"`
|
|
|
|
Username string `mapstructure:"username"`
|
|
|
|
Password string `mapstructure:"password"`
|
|
|
|
From string `mapstructure:"from"`
|
2024-02-26 12:30:53 +00:00
|
|
|
}
|
2024-02-28 13:47:33 +00:00
|
|
|
|
|
|
|
func (m MailConfig) Validate() error {
|
|
|
|
if m.Host == "" {
|
|
|
|
return errors.New("host is required")
|
|
|
|
}
|
|
|
|
if m.Username == "" {
|
|
|
|
return errors.New("username is required")
|
|
|
|
}
|
|
|
|
if m.Password == "" {
|
|
|
|
return errors.New("password is required")
|
|
|
|
}
|
2024-03-15 11:30:39 +00:00
|
|
|
if m.From == "" {
|
|
|
|
return errors.New("from is required")
|
|
|
|
}
|
2024-02-28 13:47:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
2024-03-15 11:39:43 +00:00
|
|
|
func (c MailConfig) Defaults() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"auth_type": "plain",
|
|
|
|
}
|
|
|
|
}
|