Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "validate", Short: "Starts the validator HTTP server", Run: func(cmd *cobra.Command, args []string) { addr := flag.String("addr", ":8080", "listen address") debug := flag.Bool("debug", false, "enable debug logging") flag.Parse() specPath := os.Getenv("OPENAPI_SPEC") if specPath == "" { specPath = defaultSpecPath } level := slog.LevelInfo if *debug { level = slog.LevelDebug } logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level})) slog.SetDefault(logger) validator, err := newSpecValidator(specPath, true) if err != nil { logger.Error("openapi validator setup failed", "err", err) os.Exit(1) } r := gin.New() r.Use(gin.Recovery()) r.Use(validator) registerHealthzRoute(r) registerServiceInfoRoute(r) srv := &http.Server{ Addr: *addr, Handler: r, ReadHeaderTimeout: 5 * time.Second, } logger.Info("listening", "addr", *addr) if err := srv.ListenAndServe(); err != nil { logger.Error("validator server exited", "err", err) } }, }
main is the entry point of the HTTP server binary.
It performs the following steps:
1\) Parses CLI flags for listen address and debug logging. 2\) Determines the OpenAPI spec path from environment or default. 3\) Builds a structured logger, honoring the debug flag. 4\) Constructs an OpenAPI validator middleware from the spec file. 5\) Creates a Gin router and attaches middleware and routes. 6\) Starts an HTTP server with sensible timeouts.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.