Documentation ¶
Overview ¶
Package app contains functionality related to creating an integrated environment with all the necessary dependencies.
The goal with this package is to provide a single, reusable base for interacting with the various functions provided by the motki library.
This package imports every other motki library package. As such, it cannot be imported from the "library" portion of the project. It is intended to be used from an external package.
This package provides two types of environments: client-only, and client/server.
Client-only environments, represented by ClientEnv, only contain client- side logic and require a remote motki grpc server to provide data.
Client/server environments, represented by Env, contain both the client- side services and server-side services, including a grpc server.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientEnv ¶
type ClientEnv struct { Logger log.Logger Scheduler *worker.Scheduler Client client.Client // contains filtered or unexported fields }
A ClientEnv is an environment without any server-side components.
For a ClientEnv to function, it must connect to a remote motki grpc server.
func NewClientEnv ¶
NewClientEnv creates a ClientEnv using the given configuration. A ClientEnv will not have an associated gRPC server, nor any database, or eveapi, etc.
Example ¶
ExampleNewClientEnv shows the bare-minimum to connect to the public MOTKI application and start an interactive CLI session.
Under go test and godoc sandboxes this example will always fail to create the ClientEnv because there is no network available.
package main import ( "fmt" "github.com/motki/core/app" "github.com/motki/core/log" "github.com/motki/core/proto" "github.com/motki/core/proto/client" ) func main() { conf := &app.Config{ Backend: proto.Config{ Kind: proto.BackendRemoteGRPC, RemoteGRPC: proto.RemoteConfig{ServerAddr: "motki.org:18443"}, }, Logging: log.Config{ Level: "debug", }, } // Create the application environment. env, err := app.NewClientEnv(conf) if err != nil { if err == client.ErrBadCredentials { fmt.Println("Invalid username or password.") } panic("motki: error initializing application environment: " + err.Error()) } // This method call will always fail when ran under the godoc sandbox without network access. corp, err := env.Client.GetCorporation(98513229) if err != nil { fmt.Println("motki: error getting corporation: " + err.Error()) } fmt.Println(corp.Name) }
Output: Moritake Industries
func (*ClientEnv) BlockUntilSignal ¶
BlockUntilSignal will block until it receives a signal.
This function performs the default shutdown procedure when it receives a signal.
See BlockUntilSignalWith for more details.
func (*ClientEnv) BlockUntilSignalWith ¶
func (env *ClientEnv) BlockUntilSignalWith(signals chan os.Signal, fns ...ShutdownFunc) error
BlockUntilSignalWith will block until it receives the signals signal.
This function attempts to perform a graceful shutdown, shutting down all services and doing whatever clean up processes are necessary.
Each pre-exit task exists in the form of a ShutdownFunc. Each ShutdownFunc is run concurrently and there is a finite amount of time for them to return before the application exits anyway.
type Config ¶
type Config struct { Logging log.Config `toml:"logging"` Database db.Config `toml:"db"` EVEAPI eveapi.Config `toml:"eveapi"` Backend proto.Config `toml:"backend"` }
Config represents the configuration of an Env or ClientEnv.
Note that the Database and EVEAPI Config structs may not be populated if the intent is to use the Config for creating a ClientEnv.
func NewConfigFromTOMLFile ¶
NewConfigFromTOMLFile loads a TOML configuration from the given path.
type Env ¶
type Env struct { *ClientEnv DB *db.ConnPool Model *model.Manager EveCentral *evemarketer.EveMarketer EveDB *evedb.EveDB EveAPI *eveapi.EveAPI // GRPC application server. Server server.Server // contains filtered or unexported fields }
An Env is a fully integrated environment.
This struct contains all the client and server services provided by the motki library. It does not contain any web or mail server related services.
type ShutdownFunc ¶
type ShutdownFunc func()
ShutdownFunc is a simple function intended to be called prior to application exit.