Fix mail templates embed path

This commit is contained in:
Melon 2024-09-21 16:56:05 +01:00
parent e869ee619c
commit 61d935e3c3
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
3 changed files with 8 additions and 4 deletions

View File

@ -14,6 +14,7 @@ import (
"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"
"os" "os"
@ -47,7 +48,7 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
if os.IsNotExist(err) { if os.IsNotExist(err) {
logger.Logger.Error("Missing config file") logger.Logger.Error("Missing config file")
} else { } else {
logger.Logger.Error("Open config file: ", "err", err) logger.Logger.Error("Open config file", "err", err)
} }
return subcommands.ExitFailure return subcommands.ExitFailure
} }
@ -55,7 +56,7 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
var conf startUpConfig var conf startUpConfig
err = yaml.NewDecoder(openConf).Decode(&conf) err = yaml.NewDecoder(openConf).Decode(&conf)
if err != nil { if err != nil {
logger.Logger.Error("Invalid config file: ", "err", err) logger.Logger.Error("Invalid config file", "err", err)
return subcommands.ExitFailure return subcommands.ExitFailure
} }
@ -64,7 +65,7 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
return subcommands.ExitSuccess return subcommands.ExitSuccess
} }
//go:embed mail-templates/*.go.* //go:embed mail-templates/*
var mailTemplates embed.FS var mailTemplates embed.FS
func normalLoad(conf startUpConfig, wd string) { func normalLoad(conf startUpConfig, wd string) {
@ -74,7 +75,7 @@ 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, "mail", mailTemplates) mail, err := simplemail.New(&conf.Mail.Mail, wd, cdfs.CD(mailTemplates, "mail-templates"))
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)
} }

1
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/julienschmidt/httprouter v1.3.0 github.com/julienschmidt/httprouter v1.3.0
github.com/mattn/go-sqlite3 v1.14.23 github.com/mattn/go-sqlite3 v1.14.23
github.com/miekg/dns v1.1.62 github.com/miekg/dns v1.1.62
github.com/mrmelon54/cdfs v0.0.1
github.com/mrmelon54/certgen v0.0.2 github.com/mrmelon54/certgen v0.0.2
github.com/mrmelon54/exit-reload v0.0.2 github.com/mrmelon54/exit-reload v0.0.2
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0

2
go.sum
View File

@ -91,6 +91,8 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ= github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
github.com/mrmelon54/cdfs v0.0.1 h1:2rXEG2FyaFCzqTxpQUqAe33qg7elFGtx5t0C40gnZ+0=
github.com/mrmelon54/cdfs v0.0.1/go.mod h1:KabnngCXjgEh5FjfqEuUuuiiHYpxU+Y8lPCgmUDRBYg=
github.com/mrmelon54/certgen v0.0.2 h1:4CMDkA/gGZu+E4iikU+5qdOWK7qOQrk58KtUfnmyYmY= github.com/mrmelon54/certgen v0.0.2 h1:4CMDkA/gGZu+E4iikU+5qdOWK7qOQrk58KtUfnmyYmY=
github.com/mrmelon54/certgen v0.0.2/go.mod h1:vwrWSXQmxZYqEyh+cf05IvDIFV2aYuxL4+O6ABIlN8M= github.com/mrmelon54/certgen v0.0.2/go.mod h1:vwrWSXQmxZYqEyh+cf05IvDIFV2aYuxL4+O6ABIlN8M=
github.com/mrmelon54/exit-reload v0.0.2 h1:vqgfrMD/bF21HkDsWgg5+NLjFDrD3KGVEN/iTrMn9Ms= github.com/mrmelon54/exit-reload v0.0.2 h1:vqgfrMD/bF21HkDsWgg5+NLjFDrD3KGVEN/iTrMn9Ms=