Update config and template loading

This commit is contained in:
Melon 2024-09-22 23:30:06 +01:00
parent 61d935e3c3
commit f3207389a0
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
8 changed files with 39 additions and 8 deletions

View File

@ -20,6 +20,6 @@ type acmeConfig struct {
} }
type mailConfig struct { type mailConfig struct {
simplemail.Mail simplemail.Mail `yaml:",inline"`
To simplemail.FromAddress `yaml:"to"` To simplemail.FromAddress `yaml:"to"`
} }

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Failed to find</title>
</head>
<body>
<h1>Hello</h1>
<p>World</p>
</body>
</html>

View File

@ -0,0 +1 @@
Failed to find

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"embed" "embed"
"errors"
"flag" "flag"
"github.com/1f349/mjwt" "github.com/1f349/mjwt"
"github.com/1f349/orchid" "github.com/1f349/orchid"
@ -10,13 +11,14 @@ import (
"github.com/1f349/orchid/logger" "github.com/1f349/orchid/logger"
"github.com/1f349/orchid/renewal" "github.com/1f349/orchid/renewal"
"github.com/1f349/orchid/servers" "github.com/1f349/orchid/servers"
"github.com/1f349/overlapfs"
"github.com/1f349/simplemail" "github.com/1f349/simplemail"
"github.com/1f349/violet/utils" "github.com/1f349/violet/utils"
"github.com/google/subcommands" "github.com/google/subcommands"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/mrmelon54/cdfs"
"github.com/mrmelon54/exit-reload" "github.com/mrmelon54/exit-reload"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"io/fs"
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
@ -75,10 +77,28 @@ func normalLoad(conf startUpConfig, wd string) {
logger.Logger.Fatal("Failed to load MJWT verifier public key from file", "path", filepath.Join(wd, "keys"), "err", err) logger.Logger.Fatal("Failed to load MJWT verifier public key from file", "path", filepath.Join(wd, "keys"), "err", err)
} }
mail, err := simplemail.New(&conf.Mail.Mail, wd, cdfs.CD(mailTemplates, "mail-templates")) // get mail templates
mailDir := filepath.Join(wd, "mail-templates")
err = os.Mkdir(mailDir, os.ModePerm)
if err != nil && !errors.Is(err, os.ErrExist) {
return
}
wdFs := os.DirFS(mailDir)
mailTemplatesSub, err := fs.Sub(mailTemplates, "mail-templates")
if err != nil {
logger.Logger.Fatal("Failed to load embedded mail templates", "err", err)
}
templatesFS := overlapfs.OverlapFS{A: mailTemplatesSub, B: wdFs}
// create mail sender
mail, err := simplemail.New(&conf.Mail.Mail, templatesFS)
if err != nil { if err != nil {
logger.Logger.Fatal("Failed to load email sender", "err", err) logger.Logger.Fatal("Failed to load email sender", "err", err)
} }
err = mail.Send("failed-to-find", "Test subject", conf.Mail.To.Address, map[string]any{})
if err != nil {
logger.Logger.Fatal("Failed to send start up mail", "err", err)
}
// open sqlite database // open sqlite database
db, err := orchid.InitDB(filepath.Join(wd, "orchid.db.sqlite")) db, err := orchid.InitDB(filepath.Join(wd, "orchid.db.sqlite"))

4
go.mod
View File

@ -4,7 +4,8 @@ go 1.23.1
require ( require (
github.com/1f349/mjwt v0.4.1 github.com/1f349/mjwt v0.4.1
github.com/1f349/simplemail v0.0.4 github.com/1f349/overlapfs v0.0.1
github.com/1f349/simplemail v0.0.5
github.com/1f349/violet v0.0.14 github.com/1f349/violet v0.0.14
github.com/AlecAivazis/survey/v2 v2.3.7 github.com/AlecAivazis/survey/v2 v2.3.7
github.com/charmbracelet/log v0.4.0 github.com/charmbracelet/log v0.4.0
@ -24,7 +25,6 @@ require (
) )
require ( require (
github.com/1f349/overlapfs v0.0.1 // indirect
github.com/1f349/rsa-helper v0.0.2 // indirect github.com/1f349/rsa-helper v0.0.2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/becheran/wildmatch-go v1.0.0 // indirect github.com/becheran/wildmatch-go v1.0.0 // indirect

4
go.sum
View File

@ -4,8 +4,8 @@ github.com/1f349/overlapfs v0.0.1 h1:LAxBolrXFAgU0yqZtXg/C/aaPq3eoQSPpBc49BHuTp0
github.com/1f349/overlapfs v0.0.1/go.mod h1:I6aItQycr7nrzplmfNXp/QF9tTmKRSgY3fXmu/7Ky2o= github.com/1f349/overlapfs v0.0.1/go.mod h1:I6aItQycr7nrzplmfNXp/QF9tTmKRSgY3fXmu/7Ky2o=
github.com/1f349/rsa-helper v0.0.2 h1:N/fLQqg5wrjIzG6G4zdwa5Xcv9/jIPutCls9YekZr9U= github.com/1f349/rsa-helper v0.0.2 h1:N/fLQqg5wrjIzG6G4zdwa5Xcv9/jIPutCls9YekZr9U=
github.com/1f349/rsa-helper v0.0.2/go.mod h1:VUQ++1tYYhYrXeOmVFkQ82BegR24HQEJHl5lHbjg7yg= github.com/1f349/rsa-helper v0.0.2/go.mod h1:VUQ++1tYYhYrXeOmVFkQ82BegR24HQEJHl5lHbjg7yg=
github.com/1f349/simplemail v0.0.4 h1:wPL/BjqC+VkKd2+4/CAY6Srqah/jffAo8OARvgiB1bQ= github.com/1f349/simplemail v0.0.5 h1:cr+8pdWhFE/+XVSO7ZTjntySbmIbTqmDy2SR9cHAPLE=
github.com/1f349/simplemail v0.0.4/go.mod h1:ppAIqkvVkI6L99EefbR5NgOjpePNK/RKgeoehj5A+kU= github.com/1f349/simplemail v0.0.5/go.mod h1:ppAIqkvVkI6L99EefbR5NgOjpePNK/RKgeoehj5A+kU=
github.com/1f349/violet v0.0.14 h1:MpBZ4n1dJjdiIwYMTfh0PBIFll3kjqowxR6DLasafqE= github.com/1f349/violet v0.0.14 h1:MpBZ4n1dJjdiIwYMTfh0PBIFll3kjqowxR6DLasafqE=
github.com/1f349/violet v0.0.14/go.mod h1:iAREhm+wxnGXkmuvmBhOuhUx2T7/5w7stLYNgQGbqC8= github.com/1f349/violet v0.0.14/go.mod h1:iAREhm+wxnGXkmuvmBhOuhUx2T7/5w7stLYNgQGbqC8=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=