baseplate

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

README

baseplate.go

Baseplate implemented in go.

Documentation

Code documentation

IDE/Editor setup

See here.

Code style guide

See here.

Thrift generated files

The internal/gen-go/ directory contains thrift generated files, with *-remote directories removed. They are excluded from the linter. DO NOT EDIT.

They were generated with thrift compiler 0.13.0 and baseplate.thrift using command under internal/:

thrift --gen go:package_prefix=github.com/reddit/baseplate.go/ path/to/baseplate.thrift

They are needed by edgecontext package. We did not include baseplate.thrift file into this repo to avoid duplications. This directory will be regenerated when either thrift compiler or baseplate.thrift changed significantly.

Bazel support

This project also comes with optional Bazel support. It's optional as in you can totally ignore Bazel and still use the go toolchain, but the added support will make it easier for projects using Bazel to add this project as a dependency.

When you made a change to go.mod file, please run the following command to reflect the changes in Bazel:

bazel run //:gazelle -- update-repos -from_file=go.mod -prune

Or just use the script we used in CI:

./scripts/bazel_cleanup.sh

To run tests via Bazel, use the following command:

bazel test //...:all

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

func Serve(ctx context.Context, server Server) error

Serve runs the given Server until it is given an external shutdown signal using runtimebp.HandleShutdown to handle the signal and shut down the server gracefully. Returns the (possibly nil) error returned by "Close" or context.DeadlineExceeded if it times out.

If a StopTimeout is configure, 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() *edgecontext.Impl
	Secrets() *secrets.Store
}

Baseplate is the general purpose object that you build a Server on.

func New

func New(ctx context.Context, path string, serviceCfg interface{}) (context.Context, Baseplate, error)

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.

serviceCfg is 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.

func NewTestBaseplate

func NewTestBaseplate(cfg Config, store *secrets.Store) 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 initialialize 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:"setry"`
	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

func ParseConfig(path string, serviceCfg interface{}) (Config, error)

ParseConfig returns a new Config parsed from the YAML file at the given path.

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 batcherror provides BatchError, which can be used to compile multiple errors into a single one.
Package batcherror provides BatchError, which can be used to compile multiple errors into a single one.
Package clientpool provides implementations of a generic client pool.
Package clientpool provides implementations of a generic client pool.
Package edgecontext implements Baseplate edge request context.
Package edgecontext implements Baseplate edge request context.
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 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.
Package redisbp provides Baseplate integrations for go-redis.
Package redisbp provides Baseplate integrations for go-redis.
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL