Documentation
¶
Overview ¶
Package baseplate provides a batteries-included starting point for services using Baseplate.go.
This package provides convenient initialization bundles needed in your main function, and initialize the subpackages for you. For concrete features provided by Baseplate.go packages, please refer to the documentation of the subdirectories.
For an example of how your main function should look like, please refer to https://pkg.go.dev/github.com/reddit/baseplate.go/thriftbp?tab=doc#example-NewBaseplateServer for thrift services and https://pkg.go.dev/github.com/reddit/baseplate.go/httpbp?tab=doc#example-NewBaseplateServer for HTTP services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Serve ¶
Serve runs the given Server until it is given an external shutdown signal.
It uses runtimebp.HandleShutdown to handle the signal and gracefully shut down, in order:
* any provided PreShutdown closers,
* the Server, and
* any provided PostShutdown closers.
Returns the (possibly nil) error returned by "Close", or context.DeadlineExceeded if it times out.
If a StopTimeout is configured, Serve will wait for that duration for the server to stop before timing out and returning to force a shutdown.
This is the recommended way to run a Baseplate Server rather than calling server.Start/Stop directly.
Types ¶
type Baseplate ¶
type Baseplate interface {
io.Closer
Config() Config
EdgeContextImpl() ecinterface.Interface
Secrets() *secrets.Store
}
Baseplate is the general purpose object that you build a Server on.
func New ¶
New parses the config file at the given path, initializes the monitoring and logging frameworks, and returns the "serve" context and a new Baseplate to run your service on. The returned context will be cancelled when the Baseplate is closed.
func NewTestBaseplate ¶
func NewTestBaseplate(args NewTestBaseplateArgs) Baseplate
NewTestBaseplate returns a new Baseplate using the given Config and secrets Store that can be used in testing.
NewTestBaseplate only returns a Baseplate, it does not initialize any of the monitoring or logging frameworks.
type Config ¶
type Config struct {
// Addr is the local address to run your server on.
//
// It should be in the format "${IP}:${Port}", "localhost:${Port}",
// or simply ":${Port}".
Addr string `yaml:"addr"`
// Timeout is the socket connection timeout for Servers that
// support that.
Timeout time.Duration `yaml:"timeout"`
// StopTimeout is the timeout for the Stop command for the service.
//
// If this is not set, then a default value of 30 seconds will be used.
// If this is less than 0, then no timeout will be set on the Stop command.
StopTimeout time.Duration `yaml:"stopTimeout"`
Log log.Config `yaml:"log"`
Metrics metricsbp.Config `yaml:"metrics"`
Runtime runtimebp.Config `yaml:"runtime"`
Secrets secrets.Config `yaml:"secrets"`
Sentry log.SentryConfig `yaml:"sentry"`
Tracing tracing.Config `yaml:"tracing"`
}
Config is a general purpose config for assembling a Baseplate server
func DecodeConfigYAML ¶
func DecodeConfigYAML(reader io.ReadSeeker, serviceCfg interface{}) (Config, error)
DecodeConfigYAML returns a new Config built from decoding the YAML read from the given Reader.
func ParseConfig ¶
ParseConfig returns a new Config parsed from the YAML file at the given path.
type NewArgs ¶ added in v0.8.0
type NewArgs struct {
// Required.
ConfigPath string
// Required. New will panic if this is not set.
//
// The factory to be used to create edge context implementation.
EdgeContextFactory ecinterface.Factory
// Optional.
//
// If it is non-nil, it should be a pointer and New will also decode the
// config file at the path to set it up.
// This can be used to parse additional, service specific config values from
// the same config file.
ServiceCfg interface{}
}
NewArgs defines the args used in New functino.
type NewTestBaseplateArgs ¶ added in v0.8.0
type NewTestBaseplateArgs struct {
Config Config
Store *secrets.Store
EdgeContextImpl ecinterface.Interface
}
NewTestBaseplateArgs defines the args used by NewTestBaseplate.
type ServeArgs ¶ added in v0.7.0
type ServeArgs struct {
// Server is the Server that should be run until receiving a shutdown signal.
// This is a required argument and baseplate.Serve will panic if this is nil.
Server Server
// PreShutdown is an optional slice of io.Closers that should be gracefully
// shut down before the server upon receipt of a shutdown signal.
PreShutdown []io.Closer
// PostShutdown is an optional slice of io.Closers that should be gracefully
// shut down after the server upon receipt of a shutdown signal.
PostShutdown []io.Closer
}
ServeArgs provides a list of arguments to Serve.
type Server ¶
type Server interface {
// Close should stop the server gracefully and only return after the server has
// finished shutting down.
//
// It is recommended that you use baseplate.Serve() rather than calling Close
// directly as baseplate.Serve will manage starting your service as well as
// shutting it down gracefully in response to a shutdown signal.
io.Closer
// Baseplate returns the Baseplate object the server is built on.
Baseplate() Baseplate
// Serve should start the Server on the Addr given by the Config and only
// return once the Server has stopped.
//
// It is recommended that you use baseplate.Serve() rather than calling Serve
// directly as baseplate.Serve will manage starting your service as well as
// shutting it down gracefully.
Serve() error
}
Server is the primary interface for baseplate servers.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package batchcloser provides an object "BatchCloser" that collects multiple io.Closers and closes them all when Closers.Close is called.
|
Package batchcloser provides an object "BatchCloser" that collects multiple io.Closers and closes them all when Closers.Close is called. |
|
Package breakerbp integrates with https://github.com/sony/gobreaker and provides a thrift compatible circuit breaker implementation.
|
Package breakerbp integrates with https://github.com/sony/gobreaker and provides a thrift compatible circuit breaker implementation. |
|
Package clientpool provides implementations of a generic client pool.
|
Package clientpool provides implementations of a generic client pool. |
|
Package ecinterface defines the interfaces of edgecontext package used in Baseplate.go.
|
Package ecinterface defines the interfaces of edgecontext package used in Baseplate.go. |
|
Package errorsbp provides some error utilities for Baseplate.go project.
|
Package errorsbp provides some error utilities for Baseplate.go project. |
|
Package events implements event publisher per baseplate spec.
|
Package events implements event publisher per baseplate spec. |
|
Package experiments provides implementation of experiments config parsing and other experiments related features according to baseplate spec.
|
Package experiments provides implementation of experiments config parsing and other experiments related features according to baseplate spec. |
|
Package filewatcher provides a go implementation of baseplate's FileWatcher: https://baseplate.readthedocs.io/en/stable/baseplate/file_watcher.html
|
Package filewatcher provides a go implementation of baseplate's FileWatcher: https://baseplate.readthedocs.io/en/stable/baseplate/file_watcher.html |
|
Package httpbp provides Baseplate specific helpers and integrations for http services.
|
Package httpbp provides Baseplate specific helpers and integrations for http services. |
|
internal
|
|
|
Package kafkabp provides Apache Kafka library implementations.
|
Package kafkabp provides Apache Kafka library implementations. |
|
Package log provides a wrapped zap logger interface for microservices to use, and also a simple Wrapper interface to be used by other Baseplate.go packages.
|
Package log provides a wrapped zap logger interface for microservices to use, and also a simple Wrapper interface to be used by other Baseplate.go packages. |
|
Package metricsbp provides metrics related features for baseplate.go, based on go-kit metrics package.
|
Package metricsbp provides metrics related features for baseplate.go, based on go-kit metrics package. |
|
Package mqsend is a pure go implementation of posix message queue for Linux, using syscalls.
|
Package mqsend is a pure go implementation of posix message queue for Linux, using syscalls. |
|
Package randbp provides some random generator related features: 1.
|
Package randbp provides some random generator related features: 1. |
|
redis
|
|
|
deprecated/redisbp
Package redisbp provides Baseplate integrations for go-redis.
|
Package redisbp provides Baseplate integrations for go-redis. |
|
redispipebp
Package redispipebp provides baseplate.go integrations for the redispipe library that conform to the redix.Sync interface.
|
Package redispipebp provides baseplate.go integrations for the redispipe library that conform to the redix.Sync interface. |
|
redisx
Package redisx wraps https://github.com/joomcode/redispipe in an interface where rather than returning the result, you pass in a pointer to the variable you want to put the result into and it uses reflection to do that.
|
Package redisx wraps https://github.com/joomcode/redispipe in an interface where rather than returning the result, you pass in a pointer to the variable you want to put the result into and it uses reflection to do that. |
|
Package retrybp integrates with https://github.com/avast/retry-go that provides some baseplate-specific logic and changes some defaults.
|
Package retrybp integrates with https://github.com/avast/retry-go that provides some baseplate-specific logic and changes some defaults. |
|
Package runtimebp provides extensions to the stdlib runtime package.
|
Package runtimebp provides extensions to the stdlib runtime package. |
|
Package secrets provides the functionality to access secrets from Vault by reading them out of a JSON file with automatic refresh on change.
|
Package secrets provides the functionality to access secrets from Vault by reading them out of a JSON file with automatic refresh on change. |
|
Package signing implements Baseplate's message signing protocol.
|
Package signing implements Baseplate's message signing protocol. |
|
Package thriftbp provides Baseplate specific thrift related helpers.
|
Package thriftbp provides Baseplate specific thrift related helpers. |
|
thrifttest
Package thrifttest contains objects and utility methods to aid with testing code using Thrift clients and servers.
|
Package thrifttest contains objects and utility methods to aid with testing code using Thrift clients and servers. |
|
Package timebp defines some time related types used by various baseplate components, along with their helper functions.
|
Package timebp defines some time related types used by various baseplate components, along with their helper functions. |
|
Package tracing provides tracing integration with zipkin.
|
Package tracing provides tracing integration with zipkin. |