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 ¶
func Recover ¶ added in v0.10.0
func Recover(err *error)
Recover calls [recover] and if a value is captured it will be wrapped into a PanicError. The PanicError will then be joined with any value, err, may reference. The joining is performed using errors.Join.
func Run ¶ added in v0.6.0
Run executes the application. It's responsible for reading the provided config sources, unmarshalling them into the generic config type, using the config and builder to build the users App and, lastly, running the returned App.
Example ¶
package main
import (
"context"
"fmt"
"strings"
"github.com/z5labs/bedrock/pkg/config"
)
type appFunc func(context.Context) error
func (f appFunc) Run(ctx context.Context) error {
return f(ctx)
}
func main() {
r := strings.NewReader(`hello: world`)
// Define a custom config struct which aligns with your
// the format of your config.Source(s).
type MyConfig struct {
Hello string `config:"hello"`
}
// Define a AppBuilder.
builder := AppBuilderFunc[MyConfig](func(ctx context.Context, cfg MyConfig) (App, error) {
// Inside your AppBuilder.Build is where you should be initializing
// all dependencies of your code e.g. backend API clients, DB connections, etc.
// Lastly, initialize something which implements the bedrock.App interface.
app := appFunc(func(c context.Context) error {
fmt.Println("hello,", cfg.Hello)
return nil
})
return app, nil
})
err := Run(context.Background(), builder, config.FromYaml(r))
if err != nil {
fmt.Println(err)
return
}
}
Output: hello, world
Types ¶
type AppBuildError ¶ added in v0.6.0
type AppBuildError struct {
Cause error
}
AppBuildError
func (AppBuildError) Error ¶ added in v0.6.0
func (e AppBuildError) Error() string
Error implements the [builtin.error] interface.
type AppBuilder ¶ added in v0.6.0
AppBuilder represents anything which can initialize a Runtime.
type AppBuilderFunc ¶ added in v0.6.0
AppBuilderFunc is a functional implementation of the AppBuilder interface.
type AppRunError ¶ added in v0.6.0
type AppRunError struct {
Cause error
}
AppRunError
func (AppRunError) Error ¶ added in v0.6.0
func (e AppRunError) Error() string
Error implements the [builtin.error] interface.
type ConfigReadError ¶ added in v0.6.0
type ConfigReadError struct {
Cause error
}
ConfigReadError
func (ConfigReadError) Error ¶ added in v0.6.0
func (e ConfigReadError) Error() string
Error implements the [builtin.error] interface.
type ConfigUnmarshalError ¶ added in v0.6.0
type ConfigUnmarshalError struct {
Cause error
}
ConfigUnmarshalError
func (ConfigUnmarshalError) Error ¶ added in v0.6.0
func (e ConfigUnmarshalError) Error() string
Error implements the [builtin.error] interface.
type PanicError ¶ added in v0.10.0
type PanicError struct {
Value any
}
PanicError represents a value that was recovered from a panic.
func (PanicError) Error ¶ added in v0.10.0
func (e PanicError) Error() string
Error implements the [error] interface.
func (PanicError) Unwrap ¶ added in v0.10.0
func (e PanicError) Unwrap() error
Unwrap implements the interface used by errors.Unwrap, errors.Is and errors.As.
Directories
¶
| Path | Synopsis |
|---|---|
|
circuit
module
|
|
|
example
|
|
|
custom_framework/echo
command
|
|
|
simple_queue
command
|
|
|
simple_rest
command
|
|
|
fit
module
|
|
|
host
module
|
|
|
pkg
|
|
|
app
Package app provides helpers for common bedrock.App implementation patterns.
|
Package app provides helpers for common bedrock.App implementation patterns. |
|
appbuilder
Package appbuilder provides helpers for common bedrock.AppBuilder implementation patterns.
|
Package appbuilder provides helpers for common bedrock.AppBuilder implementation patterns. |
|
config
Package config provides very easy to use and extensible configuration management capabilities.
|
Package config provides very easy to use and extensible configuration management capabilities. |
|
config/key
Package key provides types for strongly typed keys in key value pairs.
|
Package key provides types for strongly typed keys in key value pairs. |
|
health
Package health defines K8s inspired health metrics.
|
Package health defines K8s inspired health metrics. |
|
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. |
|
ptr
Package ptr provides helpers for working with references of values.
|
Package ptr provides helpers for working with references of values. |
|
Package queue provides multiple patterns which implements the app.Runtime interface.
|
Package queue provides multiple patterns which implements the app.Runtime interface. |
|
Package rest provides a bedrock.App implementation for building RESTful applications.
|
Package rest provides a bedrock.App implementation for building RESTful applications. |
|
endpoint
Package endpoint wraps generic RPC style code into a RESTful HTTP endpoint handler.
|
Package endpoint wraps generic RPC style code into a RESTful HTTP endpoint handler. |
|
mux
Package mux defines a simple API for all http multiplexers to implement.
|
Package mux defines a simple API for all http multiplexers to implement. |
|
retry
module
|