check / check (push) Failing after 2s
cmd/pixad/main.go built the command line and its --config flag, set PIXA_CONFIG_PATH from that flag, ignored SIGPIPE and started the fx app. REPO_POLICIES.md now requires cmd/ to hold only one call into internal/ or pkg/, so that code moves unchanged to Run in the new internal/app package, and main calls app.Run(Version). Version stays in main, so the -X main.Version build flags in the Dockerfile and the Makefile do not change. Model: opus-5-5
71 wiersze
1.6 KiB
Go
71 wiersze
1.6 KiB
Go
// Package app reads the pixad command line and runs the server.
|
|
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/spf13/cobra"
|
|
"go.uber.org/fx"
|
|
"sneak.berlin/go/pixa/internal/config"
|
|
"sneak.berlin/go/pixa/internal/database"
|
|
"sneak.berlin/go/pixa/internal/globals"
|
|
"sneak.berlin/go/pixa/internal/handlers"
|
|
"sneak.berlin/go/pixa/internal/healthcheck"
|
|
"sneak.berlin/go/pixa/internal/logger"
|
|
"sneak.berlin/go/pixa/internal/middleware"
|
|
"sneak.berlin/go/pixa/internal/server"
|
|
)
|
|
|
|
var configPath string //nolint:gochecknoglobals // cobra flag
|
|
|
|
// Run reads the command line and runs the server until it stops, with
|
|
// version as the version pixad logs and reports. It exits the process
|
|
// with status 1 when the command line is not valid.
|
|
func Run(version string) {
|
|
globals.Version = version
|
|
|
|
rootCmd := &cobra.Command{
|
|
Use: "pixad",
|
|
Short: "Pixa image caching proxy server",
|
|
Run: run,
|
|
}
|
|
|
|
rootCmd.Flags().StringVarP(&configPath, "config", "c", "", "path to config file")
|
|
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(_ *cobra.Command, _ []string) {
|
|
// Set config path in environment if specified via flag
|
|
if configPath != "" {
|
|
_ = os.Setenv("PIXA_CONFIG_PATH", configPath)
|
|
}
|
|
|
|
// A write to a closed stdout or stderr must not end the process.
|
|
signal.Ignore(syscall.SIGPIPE)
|
|
|
|
fx.New(
|
|
fx.Provide(
|
|
config.New,
|
|
database.New,
|
|
globals.New,
|
|
handlers.New,
|
|
logger.New,
|
|
server.New,
|
|
middleware.New,
|
|
healthcheck.New,
|
|
),
|
|
fx.Invoke(
|
|
func(log *logger.Logger) { log.Identify() },
|
|
func(*server.Server) {},
|
|
),
|
|
).Run()
|
|
}
|