Documentation ¶
Overview ¶
Package bedrock provides a minimal foundation for building more complex frameworks on top of.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App handles the lower level things of running a service in Go. App is responsible for the following:
- Parsing (and merging) you config(s)
- Calling your lifecycle hooks at the appropriate times
- Running your Runtime(s) and propogating any OS interrupts via context.Context cancellation
func (*App) Run ¶
Run executes the application. It also handles listening for interrupts from the underlying OS and terminates the application when one is received.
Example ¶
r := strings.NewReader(`hello: {{env "HELLO" | default "world"}}`) app := New( Name("example"), ConfigTemplateFunc("env", configtmpl.Env), ConfigTemplateFunc("default", configtmpl.Default), Config(r), WithRuntimeBuilderFunc(func(ctx context.Context) (Runtime, error) { m := ConfigFromContext(ctx) var cfg struct { Hello string `config:"hello"` } err := m.Unmarshal(&cfg) if err != nil { return nil, err } rt := runtimeFunc(func(ctx context.Context) error { fmt.Printf("hello, %s\n", cfg.Hello) return nil }) return rt, nil }), ) err := app.Run() if err != nil { fmt.Println(err) return }
Output: hello, world
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle provides the ability to hook into certain points of the bedrock App.Run process.
func LifecycleFromContext ¶
LifecycleFromContext extracts a *Lifecycle from the given context.Context if it's present.
func (*Lifecycle) PostRun ¶
PostRun registers hooks to be after Runtime.Run has completed, regardless whether it returned an error or not.
type Option ¶
type Option func(*App)
Option are used to configure an App.
func Config ¶
Config registers a config source with the application. If used multiple times, subsequent configs will be merged with the very first Config provided. The subsequent configs values will override any previous configs values.
func ConfigTemplateFunc ¶ added in v0.3.0
ConfigTemplateFunc registers the given template func with the underlying config reader so it can be used in config source templates.
func WithRuntimeBuilder ¶
func WithRuntimeBuilder(rb RuntimeBuilder) Option
WithRuntimeBuilder registers the given RuntimeBuilder with the App.
type Runtime ¶
Runtime represents the entry point for user specific code. The Runtime should not worry about things like OS interrupts and config parsing because App is responsible for managing those more "low-level" things. A Runtime should be purely focused on running use case specific code e.g. RESTful API, gRPC API, K8s Job, etc.
type RuntimeBuilder ¶
RuntimeBuilder represents anything which can initialize a Runtime.
type RuntimeBuilderFunc ¶
RuntimeBuilderFunc is a functional implementation of the RuntimeBuilder interface.
Directories ¶
Path | Synopsis |
---|---|
example
|
|
Package grpc provides a gRPC server which implements the app.Runtime interface.
|
Package grpc provides a gRPC server which implements the app.Runtime interface. |
Package http provides a HTTP server which implements the app.Runtime interface.
|
Package http provides a HTTP server which implements the app.Runtime interface. |
httpclient
Package httpclient provides a production ready http.Client.
|
Package httpclient provides a production ready http.Client. |
httphealth
Package httphealth provides a http.Handler for exposing health.Metrics
|
Package httphealth provides a http.Handler for exposing health.Metrics |
httpvalidate
Package httpvalidate provides helpers for validating incoming HTTP requests.
|
Package httpvalidate provides helpers for validating incoming HTTP requests. |
pkg
|
|
config
Package config provides a useful wrapper for the popular spf13/viper package.
|
Package config provides a useful wrapper for the popular spf13/viper package. |
config/configtmpl
Package configtmpl provides template functions for ue in config source templates.
|
Package configtmpl provides template functions for ue in config source templates. |
health
Package health defines K8s inspired health metrics.
|
Package health defines K8s inspired health metrics. |
lifecycle
Package lifecycle provides helpers for registering common lifecycle hooks.
|
Package lifecycle provides helpers for registering common lifecycle hooks. |
maskslog
Package maskslog provides a slog.Handler which includes support for masking slog.Attrs.
|
Package maskslog provides a slog.Handler which includes support for masking slog.Attrs. |
noop
Package noop provides no-op implementations to be used in tests and as defaults.
|
Package noop provides no-op implementations to be used in tests and as defaults. |
otelconfig
Package otelconfig provides helpers for initializing specific trace.TracerProviders.
|
Package otelconfig provides helpers for initializing specific trace.TracerProviders. |
otelslog
Package otelslog provides a OpenTelemetry aware slog.Handler implementation.
|
Package otelslog provides a OpenTelemetry aware slog.Handler implementation. |
slogfield
Package slogfield re-exports and provides extra slog.Attrs.
|
Package slogfield re-exports and provides extra slog.Attrs. |
Package queue provides multiple patterns which implements the app.Runtime interface.
|
Package queue provides multiple patterns which implements the app.Runtime interface. |
pubsub
Package pubsub provides default implementations for using Google Cloud PubSub with the runtimes in the queue package.
|
Package pubsub provides default implementations for using Google Cloud PubSub with the runtimes in the queue package. |
sqs
Package sqs provides default implementations for using AWS SQS with the runtimes in the queue package.
|
Package sqs provides default implementations for using AWS SQS with the runtimes in the queue package. |
sqs/sqsslog
Package sqsslog provides slog helpers for SQS related data fields.
|
Package sqsslog provides slog helpers for SQS related data fields. |