app

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFile

func LoadFile(fileURL string) ([]byte, error)

LoadFile loads a file at the specified URL using the corresponding registered FileLoader. If no scheme is specified, LocalLoader is used.

func RegisterFileLoaderCtor

func RegisterFileLoaderCtor(scheme string, ctr FileLoaderCtor)

RegisterFileLoaderCtor registers a FileLoader for the specified scheme.

func Run

func Run(app App, options ...Option) error

Types

type App

type App interface {
	// Init initializes the application in a blocking fashion. When Init returns, it
	// is expected that the application is ready to start receiving requests (provided
	// there are gRPC handlers installed).
	//
	// todo: I'm not very happy with passing the New Relic app here. It's a temporary
	//       solution until we have something better in place.
	Init(config Config, metricsProvider *newrelic.Application) error

	// RegisterWithGRPC provides a mechanism for the application to register gRPC services
	// with the gRPC server.
	RegisterWithGRPC(server *grpc.Server)

	// ShutdownChan returns a channel that is closed when the application is shutdown.
	//
	// If the channel is closed, the gRPC server will initiate a shutdown if it has
	// not already done so.
	ShutdownChan() <-chan struct{}

	// Stop stops the service, allowing for it to clean up any resources. When Stop()
	// returns, the process exits.
	//
	// Stop should be idempotent.
	Stop()
}

App is a long lived application that services network requests. It is expected that App's have gRPC services, but is not a hard requirement.

The lifecycle of the App is tied to the process. The app gets initialized before the gRPC server runs, and gets stopped after the gRPC server has stopped serving.

type BaseConfig

type BaseConfig struct {
	LogLevel string `mapstructure:"log_level"`

	AppName string `mapstructure:"app_name"`

	ListenAddress         string `mapstructure:"listen_address"`
	InsecureListenAddress string `mapstructure:"insecure_listen_address"`
	DebugListenAddress    string `mapstructure:"debug_listen_address"`

	// TLSCertificate is an optional URL that specified a TLS certificate to be
	// used for the gRPC server.
	//
	// Currently only two supported URL schemes are supported: file, s3.
	// If no scheme is specified, file is used.
	TLSCertificate string `mapstructure:"tls_certificate"`
	// TLSKey is an optional URL that specifies a TLS Private Key to be used for the
	// gRPC server.
	//
	// Currently only two supported URL schemes are supported: file, s3.
	// If no scheme is specified, file is used.
	TLSKey string `mapstructure:"tls_private_key"`

	ShutdownGracePeriod time.Duration `mapstructure:"shutdown_grace_period"`

	EnablePprof  bool `mapstructure:"enable_pprof"`
	EnableExpvar bool `mapstructure:"enable_expvar"`

	// Ballast for improving Go GC performance. Note that capacity will be
	// limited to 50% of the total memory.
	// https://blog.twitch.tv/en/2019/04/10/go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap/
	EnableBallast   bool    `mapstructure:"enable_ballast"`
	BallastCapacity float32 `mapstructure:"ballast_capacity"`

	// Periodically terminate the application when there's a memory leak
	EnableMemoryLeakCron   bool   `mapstructure:"enable_memory_leak_cron"`
	MemoryLeakCronSchedule string `mapstructure:"memory_leak_cron_schedule"`

	// Metrics configuration across many providers
	NewRelicLicenseKey string `mapstructure:"new_relic_license_key"`

	// Arbitrary configuration that the service can define / implement.
	//
	// Users should use mapstructure.Decode for ServiceConfig.
	AppConfig Config `mapstructure:"app"`
}

BaseConfig contains the base configuration for services, as well as the application itself.

type Config

type Config map[string]interface{}

Config is the application specific configuration. It is passed to the App.Init function, and is optional.

type FileLoader

type FileLoader interface {
	Load(url *url.URL) ([]byte, error)
}

FileLoader loads files at a specified URL.

type FileLoaderCtor

type FileLoaderCtor func() (FileLoader, error)

FileLoaderCtor constructs a FileLoader.

type Option

type Option func(o *opts)

Option configures the environment run by Run().

func WithStreamServerInterceptor

func WithStreamServerInterceptor(interceptor grpc.StreamServerInterceptor) Option

WithStreamServerInterceptor configures the app's gRPC server to use the provided interceptor.

Interceptors are evaluated in addition order, and configured interceptors are executed after the app's default interceptors.

func WithUnaryServerInterceptor

func WithUnaryServerInterceptor(interceptor grpc.UnaryServerInterceptor) Option

WithUnaryServerInterceptor configures the app's gRPC server to use the provided interceptor.

Interceptors are evaluated in addition order, and configured interceptors are executed after the app's default interceptors.

Jump to

Keyboard shortcuts

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