Documentation
¶
Index ¶
- func AsLivenessCheck(f any) any
- func AsReadinessCheck(f any) any
- func BindConfig(prefix string, value any) any
- func Config[T any](prefix string, value T) any
- func Logger(name ...string) any
- func Meter(name string, opts ...metric.MeterOption) any
- func Tracer(name string, opts ...trace.TracerOption) any
- type HealthCheck
- type Sprout
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsLivenessCheck ¶
AsLivenessCheck takes a function that returns a HealthCheck and annotates it to be invoked as a liveness check. Liveness checks will be made available on the health server at the path /healthz.
Example:
fx.Provide(sprout.AsLivenessCheck(func(depsHere...) sprout.HealthCheck {
return sprout.HealthCheck{
Name: "example",
Check: func(ctx context.Context) error {
return nil
},
}
}))
func AsReadinessCheck ¶
AsReadinessCheck takes a function that returns a HealthCheck and annotates it to be invoked as a readiness check. Readiness checks will be made available on the health server at the path /readyz.
Example:
fx.Provide(sprout.asReadinessCheck(func(depsHere...) sprout.HealthCheck {
return sprout.HealthCheck{
Name: "example",
Check: func(ctx context.Context) error {
return nil
},
}
}))
func BindConfig ¶
BindConfig is an on-demand version of Config. It will read configuration from the environment and bind them to the specified struct.
func Config ¶
Config will read configuration from the environment and provide the specified type to the application.
Example:
type Config struct {
Host string `env:"HOST" envDefault:"localhost"`
Port int `env:"PORT" envDefault:"8080"`
}
sprout.New("my-service", "1.0.0").With(
fx.Provide(sprout.Config("HTTP", Config{})),
fx.Invoke(func(config Config) {
// ...
}),
).Run()
func Logger ¶
Logger creates a function that can be used to create a logger with a name. Can be used with fx.Decorate or fx.Provide.
It is mostly used when creating a module, to supply a logger with a name that is specific to the module.
Example:
var Module = fx.Module(
"example",
fx.Decorate(sprout.Logger("name", "of", "logger")),
fx.Invoke(func(logger logr.Logger) {
// ...
}),
)