Documentation
¶
Index ¶
Constants ¶
const ( // UseProfileFieldName is the command-line flag to enable pprof endpoints. UseProfileFieldName = "trace.pprof" // EndpointFieldName is the command-line flag for pprof endpoint path. EndpointFieldName = "server.http.routes.pprof" // UseProfileDefault disables pprof by default. UseProfileDefault = false // EndpointDefault is the default path for pprof endpoints. EndpointDefault = "/debug" )
Variables ¶
var Component = &component.Component{ Dependencies: component.Components{ chi.Component, }, Init: component.StepFunc(func(container container.Container) error { return container.Provide(NewConfig) }), BindFlags: component.BindFlags(func(flagSet flag.FlagSet, container container.Container) error { return container.Invoke(func(config *Config) { flagSet.BoolVar(&config.UseProfile, UseProfileFieldName, UseProfileDefault, "if true, add debug path to routing") flagSet.StringVar(&config.Endpoint, EndpointFieldName, EndpointDefault, "path for debug endpoint") }) }), Configuration: component.StepFunc(func(container container.Container) error { return container.Invoke(Configuration) }), Execute: component.StepFunc(func(container container.Container) error { return container.Invoke(func(config *Config, r http.Router, logger logger.Logger) { if config.UseProfile { logger.Infof("[chi.router] add pprof endpoint - '%s'", config.Endpoint) r.Mount(config.Endpoint, middleware.Profiler()) } }) }), }
Component adds pprof debugging endpoints to the HTTP router when enabled. It depends on chi.Component for the router.
Usage:
compogo.WithComponents(
http.Component,
chi.Component,
pprof.Component,
)
Enable with: --trace.pprof=true --server.http.routes.pprof=/debug
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config holds the pprof configuration. It can be populated from command-line flags or config files.
func Configuration ¶
func Configuration(config *Config, configurator configurator.Configurator) *Config
Configuration applies configuration values to the Config struct. It reads from the provided configurator and sets defaults if values are not present.