auth/cmd/main.go

49 lines
1021 B
Go
Raw Normal View History

2023-10-21 08:26:15 +00:00
package main
import (
"log/slog"
"os"
"git.t-juice.club/microfilm/auth/server"
"github.com/urfave/cli/v2"
)
func main() {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
app := &cli.App{
Name: "mf-auth",
Usage: "Run microfilm auth service",
Action: func(*cli.Context) error {
// Read config
f, err := os.Open("mf-auth.toml")
if err != nil {
logger.Error("Error opening config.", "error", err)
os.Exit(1)
}
cfg, err := server.ConfigFromReader(f)
if err != nil {
logger.Error("Error parsing config.", "error", err)
os.Exit(1)
}
srv, err := server.NewServer(cfg)
if err != nil {
logger.Error("Error setting up server.", "error", err)
os.Exit(2)
}
// Start server
srv.Logger = logger
logger.Info("Starting server.", "addr", srv.Addr)
return srv.ListenAndServe()
},
}
if err := app.Run(os.Args); err != nil {
logger.Error("Error running service.", "error", err)
os.Exit(1)
}
}