proxy/cmd/main.go

49 lines
1.0 KiB
Go
Raw Permalink Normal View History

2023-10-22 21:46:41 +00:00
package main
import (
"log/slog"
"os"
"git.t-juice.club/microfilm/proxy/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-proxy",
Usage: "Run microfilm proxy service",
Action: func(c *cli.Context) error {
// Read config
f, err := os.Open("mf-proxy.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)
}
}