Add service orchestration and command
Wire the intake and answer subsystems together into a running application. - config: maps YAML file to internal package configuration. - service: manages lifecycle and graceful shutdown. - cmd/raven: entry point for flag parsing and signal handling.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
// Command raven monitors an IMAP mailbox for new messages, generates replies
|
||||
// using an LLM, and sends them via SMTP. See package service for the main
|
||||
// orchestration logic and package config for configuration options.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
"raven/internal/config"
|
||||
"raven/internal/service"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var cfgPath = flag.String(
|
||||
"c", "", "path to configuration file (required)",
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
var log = slog.New(slog.NewTextHandler(
|
||||
os.Stderr,
|
||||
&slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
Level: slog.LevelDebug,
|
||||
},
|
||||
))
|
||||
if *cfgPath == "" {
|
||||
log.Error("missing config path")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Log build info.
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
var commit, time string
|
||||
for _, s := range bi.Settings {
|
||||
switch s.Key {
|
||||
case "vcs.revision":
|
||||
commit = s.Value
|
||||
case "vcs.time":
|
||||
time = s.Value
|
||||
}
|
||||
}
|
||||
log.Debug(
|
||||
"raven",
|
||||
slog.Group(
|
||||
"build",
|
||||
slog.String("commit", commit),
|
||||
slog.String("time", time),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
cfg, err := config.Load(*cfgPath)
|
||||
if err != nil {
|
||||
log.Error(
|
||||
"failed to load config",
|
||||
slog.Any("error", err),
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
svc, err := service.New(cfg, log)
|
||||
if err != nil {
|
||||
log.Error(
|
||||
"failed to create service",
|
||||
slog.Any("error", err),
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := svc.Run(context.Background()); err != nil {
|
||||
log.Error(
|
||||
"failed to run",
|
||||
slog.Any("error", err),
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user