email
go
import "github.com/prescriptoo/prescriptoo-api/pkg/email"Package email defines the shared email delivery boundary used by services.
Index
type Console
Console prints development emails to an injected terminal/output writer. One JSON record per message escapes control characters and avoids interleaving.
go
type Console struct {
// contains filtered or unexported fields
}func NewConsole
go
func NewConsole(out io.Writer) *ConsoleNewConsole creates a console adapter. The application normally passes os.Stdout.
func (*Console) Send
go
func (c *Console) Send(ctx context.Context, message Message) errorSend prints the complete email; it does not contact an external provider.
Example
A console sender makes development delivery visible without a provider.
go
package main
import (
"context"
"os"
"github.com/prescriptoo/prescriptoo-api/pkg/email"
)
func main() {
sender := email.NewConsole(os.Stdout)
err := sender.Send(context.Background(), email.Message{
To: "doctor@example.com", Subject: "Welcome", Body: "Your account is ready.",
})
if err != nil {
panic(err)
}
}Output
{"adapter":"console-email","to":"doctor@example.com","subject":"Welcome","body":"Your account is ready."}type Message
Message is a provider-independent plain-text email.
go
type Message struct {
To string
Subject string
Body string
}type Sender
Sender delivers an email or returns a delivery error. Providers must respect cancellation and must not include message bodies or credentials in errors.
go
type Sender interface {
Send(context.Context, Message) error
}Generated by gomarkdoc