app

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(ctx Context) (config.RequestManager, error)

LoadConfig is the default LoadConfig hook. It loads the config file specified on the command line, or from config/ENVIRONMENT.yaml where ENVIRONMENT is an environment variable specifing "staging" or "production", else it defaults to "development".

func LoadSpecs

func LoadSpecs(ctx Context) (grapher.Config, error)

LoadSpecs is the default LoadSpecs hook.

func MakeDbConnPool

func MakeDbConnPool(ctx Context) (*sql.DB, error)

MakeDbConnPool is the default MakeDbConnPool factory.

func MakeGrapher

func MakeGrapher(ctx Context) (grapher.GrapherFactory, error)

MakeGrapher is the default MakeGrapher factory.

func MakeJobRunnerClient

func MakeJobRunnerClient(ctx Context) (jr.Client, error)

MakeJobRunnerClient is the default MakeJobRunnerClient factory.

Types

type Context

type Context struct {
	// User-provided config from config file
	Config config.RequestManager
	Specs  grapher.Config

	// Core service singletons, not user-configurable
	RM     request.Manager
	RR     request.Resumer
	Status status.Manager
	Auth   auth.Manager
	JLS    joblog.Store

	// Closed to initiate RM shutdown
	ShutdownChan chan struct{}

	// 3rd-party extensions, all optional
	Hooks     Hooks
	Factories Factories
	Plugins   Plugins
}

Context represents the config, core service singletons, and 3rd-party extensions. There is one immutable context shared by many packages, created in Server.Boot, called api.appCtx.

func Defaults

func Defaults() Context

Defaults returns a Context with default (built-in) 3rd-party extensions. The default context is not sufficient to run the Request Manager, but it provides the starting point for user customization by overriding the default hooks, factories, and plugins. See documentation for details.

After customizing the default context, it is used to boot the server (see server package) which loads the configs and creates the core service singleton.

type Factories

type Factories struct {
	MakeGrapher         func(Context) (grapher.GrapherFactory, error) // @fixme
	MakeJobRunnerClient func(Context) (jr.Client, error)
	MakeDbConnPool      func(Context) (*sql.DB, error)
}

Factories make objects at runtime. All factories are optional; the defaults are sufficient to run the Request Manager. Users can provide custom factories to modify behavior. For example, make Job Runner clients with custom TLS certs.

type Hooks

type Hooks struct {
	// LoadConfig loads the Request Manager config file. This hook overrides
	// the default function. Spin Cycle fails to start if it returns an error.
	LoadConfig func(Context) (config.RequestManager, error)

	// LoadSpecs loads the request specification files (specs). This hook overrides
	// the default function. Spin Cycle fails to start if it returns an error.
	LoadSpecs func(Context) (grapher.Config, error)

	// SetUsername sets proto.Request.User. The auth.Plugin.Authenticate method is
	// called first which sets the username to Caller.Name. This hook is called after
	// and overrides the username. The request fails and returns HTTP 500 if it
	// returns an error.
	SetUsername func(*http.Request) (string, error)

	// RunAPI runs the Request Manager API. It should block until the API is
	// stopped via a call to StopAPI. If this hook is provided, it is called
	// instead of api.Run(). If you provide this hook, you need to provide StopAPI
	// as well.
	RunAPI func() error

	// StopAPI stops running the Request Manager API - it's called after RunAPI
	// when the Request Manager is shutting down, and it should cause RunAPI to
	// return. If you provide this hook, you need to provide RunAPI as well.
	StopAPI func() error
}

Hooks allow users to modify system behavior at certain points. All hooks are optional; the defaults are sufficient to run the Request Manager. For example, the LoadConfig hook allows the user to load and parse the config file, completely overriding the built-in code.

type Plugins

type Plugins struct {
	Auth auth.Plugin
}

Plugins allow users to provide custom components. All plugins are optional; the defaults are sufficient to run the Request Manager. Whereas hooks are single, specific calls, plugins are complete components with more extensive functionality defined by an interface. A user plugin, if provided, must implement the interface completely. For example, the Auth plugin allows the user to provide a complete and custom system of authentication and authorization.

Jump to

Keyboard shortcuts

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