app

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 35 Imported by: 3

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).
	Init(config Config) 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"`
	LogType  string `mapstructure:"log_type"`

	ListenAddress         string        `mapstructure:"listen_address"`
	InsecureListenAddress string        `mapstructure:"insecure_listen_address"`
	ShutdownGracePeriod   time.Duration `mapstructure:"shutdown_grace_period"`

	HTTPGatewayAddress string `mapstructure:"http_gateway_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"`

	EnablePprof        bool   `mapstructure:"enable_pprof"`
	EnableExpvar       bool   `mapstructure:"enable_expvar"`
	DebugListenAddress string `mapstructure:"debug_listen_address"`

	// 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 agora 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 LocalLoader

type LocalLoader struct{}

LocalLoader is a FileLoader that loads file from the local filesystem.

func (LocalLoader) Load

func (l LocalLoader) Load(url *url.URL) ([]byte, error)

Load implements Loader.Load.

type Option

type Option func(o *opts)

Option configures the environment run by Run().

func WithHTTPGatewayEnabled added in v0.52.0

func WithHTTPGatewayEnabled(enabled bool, muxOpts ...httpgateway.MuxOption) Option

WithHTTPGatewayEnabled configures whether or not an HTTP gateway should be enabled with the provided options.

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.

type S3Loader

type S3Loader struct {
	// contains filtered or unexported fields
}

S3Loader is a FileLoader that loads files from S3.

func (S3Loader) Load

func (l S3Loader) Load(url *url.URL) ([]byte, error)

Load implements FileLoader.Load.

Jump to

Keyboard shortcuts

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