2022-07-18 00:56:09 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New creates a new templates' provider.
|
|
|
|
func New(config Config) (provider *Provider, err error) {
|
|
|
|
provider = &Provider{
|
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = provider.load(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return provider, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provider of templates.
|
|
|
|
type Provider struct {
|
|
|
|
config Config
|
|
|
|
templates Templates
|
|
|
|
}
|
|
|
|
|
2022-12-27 08:59:08 +00:00
|
|
|
func (p *Provider) GetEventEmailTemplate() (t *EmailTemplate) {
|
|
|
|
return p.templates.notification.event
|
2022-07-18 00:56:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
// GetIdentityVerificationEmailTemplate returns the EmailTemplate for Identity Verification notifications.
|
|
|
|
func (p *Provider) GetIdentityVerificationEmailTemplate() (t *EmailTemplate) {
|
|
|
|
return p.templates.notification.identityVerification
|
2022-07-18 00:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provider) load() (err error) {
|
|
|
|
var errs []error
|
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
if p.templates.notification.identityVerification, err = loadEmailTemplate(TemplateNameEmailIdentityVerification, p.config.EmailTemplatesPath); err != nil {
|
2022-07-18 00:56:09 +00:00
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
|
|
|
|
2022-12-27 08:59:08 +00:00
|
|
|
if p.templates.notification.event, err = loadEmailTemplate(TemplateNameEmailEvent, p.config.EmailTemplatesPath); err != nil {
|
2022-07-18 00:56:09 +00:00
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
if len(errs) != 0 {
|
|
|
|
for i, e := range errs {
|
|
|
|
if i == 0 {
|
|
|
|
err = e
|
|
|
|
continue
|
|
|
|
}
|
2022-07-18 00:56:09 +00:00
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
err = fmt.Errorf("%v, %w", err, e)
|
2022-07-18 00:56:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
return fmt.Errorf("one or more errors occurred loading templates: %w", err)
|
2022-07-18 00:56:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 05:06:49 +00:00
|
|
|
return nil
|
2022-07-18 00:56:09 +00:00
|
|
|
}
|