split watcher and http server from sender + add golanci config
This commit is contained in:
+17
-10
@@ -20,30 +20,29 @@ type Email struct {
|
||||
}
|
||||
|
||||
func FromJSON(path string) (Email, error) {
|
||||
var mail Email
|
||||
var email Email
|
||||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return mail, fmt.Errorf("%w, unable to read the file: %s", err, path)
|
||||
return email, fmt.Errorf("%w, unable to read the file: %s", err, path)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(content, &mail); err != nil {
|
||||
return mail, err
|
||||
if err := json.Unmarshal(content, &email); err != nil {
|
||||
return email, err
|
||||
}
|
||||
|
||||
validate = validator.New(validator.WithRequiredStructEnabled())
|
||||
if err := validate.Struct(mail); err != nil {
|
||||
return mail, err
|
||||
if err := email.Validate(); err != nil {
|
||||
return email, err
|
||||
}
|
||||
|
||||
return mail, nil
|
||||
return email, nil
|
||||
}
|
||||
|
||||
func (e Email) GetReceivers() []string {
|
||||
func (e *Email) GetReceivers() []string {
|
||||
return strings.Split(e.Receivers, ",")
|
||||
}
|
||||
|
||||
func (e Email) Generate() []byte {
|
||||
func (e *Email) Generate() []byte {
|
||||
mail := fmt.Sprintf(
|
||||
"To: %s\nFrom: %s\nContent-Type: text/html;charset=utf-8\nSubject: %s\n\n%s",
|
||||
e.Receivers,
|
||||
@@ -53,3 +52,11 @@ func (e Email) Generate() []byte {
|
||||
)
|
||||
return []byte(mail)
|
||||
}
|
||||
|
||||
func (e *Email) Validate() error {
|
||||
validate = validator.New(validator.WithRequiredStructEnabled())
|
||||
if err := validate.Struct(e); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -56,5 +56,4 @@ func TestFromJson(t *testing.T) {
|
||||
|
||||
assert.Contains(t, err.Error(), "validation for 'Sender'")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user