basic common app packages

This commit is contained in:
2025-06-16 22:19:00 +05:30
parent 8654f21b62
commit 0240ec154e
49 changed files with 5481 additions and 232 deletions

35
email/transport.go Normal file
View File

@@ -0,0 +1,35 @@
package email
import (
"os"
"path/filepath"
"time"
"code.patial.tech/go/appcore/open"
)
type Transport interface {
Send(*Message) error
}
// DumpToTemp transport is for development environment to ensure emails are renderd as HTML ok
//
// once dump operation is done it will try to open the html with default app for html
type DumpToTemp struct{}
func (DumpToTemp) Send(msg *Message) error {
// validate msg first
if err := msg.Validate(); err != nil {
return err
}
dir := os.TempDir()
id := time.Now().Format("20060102T150405999")
file := filepath.Join(dir, id+".html")
if err := os.WriteFile(file, []byte(msg.HtmlBody), 0440); err != nil {
return err
}
return open.WithDefaultApp(file)
}