mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"github.com/jwetzell/showbridge-go"
|
|
"github.com/urfave/cli/v3"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
func main() {
|
|
cmd := &cli.Command{
|
|
Name: "showbridge",
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "config",
|
|
Value: "./config.yaml",
|
|
},
|
|
},
|
|
Action: func(ctx context.Context, c *cli.Command) error {
|
|
configPath := c.String("config")
|
|
if configPath == "" {
|
|
return fmt.Errorf("config value cannot be empty")
|
|
}
|
|
|
|
config, err := readConfig(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
router, moduleErrors, routeErrors := showbridge.NewRouter(ctx, config)
|
|
for _, moduleError := range moduleErrors {
|
|
slog.Error("problem initializing module", "index", moduleError.Index, "error", moduleError.Error)
|
|
}
|
|
|
|
for _, routeError := range routeErrors {
|
|
slog.Error("problem initializing module", "index", routeError.Index, "error", routeError.Error)
|
|
}
|
|
router.Run()
|
|
return nil
|
|
},
|
|
}
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Interrupt)
|
|
defer cancel()
|
|
err := cmd.Run(ctx, os.Args)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
}
|
|
|
|
func readConfig(configPath string) (showbridge.Config, error) {
|
|
configBytes, err := os.ReadFile(configPath)
|
|
|
|
if err != nil {
|
|
return showbridge.Config{}, err
|
|
}
|
|
|
|
config := showbridge.Config{}
|
|
|
|
err = yaml.Unmarshal(configBytes, &config)
|
|
if err != nil {
|
|
return showbridge.Config{}, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|