bootstrap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2018 License: MIT Imports: 16 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBOptions

type DBOptions struct {
	Username string `toml:"username" commented:"true"`
	Password string `toml:"password" commented:"true"`
	Host     string `toml:"host" comment:"host can be 'host:port', 'host', 'host:' or ':port'"`
	DBName   string `toml:"dbname"`
}

type Duration

type Duration struct {
	time.Duration
}

Duration is a wrapper around time.Duration and allows for automatic toml string parsing of time.Duration values. Use this type in a custom config for automatic serializing and de-serializing of time.Duration.

func (*Duration) MarshalTOML

func (d *Duration) MarshalTOML() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type NilValidator

type NilValidator struct{}

NilValidator satisfies the Validator interface but does nothing.

func (*NilValidator) Validate

func (v *NilValidator) Validate() error

type Validator

type Validator interface {
	Validate() error
}

Validator provides a standard method for running underlying validation for underlying object values.

type WorkerApp

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

func NewWorkerApp

func NewWorkerApp(tskType string, newWkr task.NewWorker, options Validator) *WorkerApp

NewWorkerApp will create a new worker bootstrap application. *tskType: defines the worker type; the type of tasks the worker is expecting. Also acts as a name for identification (required) *mkr: MakeWorker function that the launcher will call to create a new worker. *options: a struct pointer to additional specific application config options. Note that

the bootstrapped WorkerApp already provides bus and launcher config options and the user
can request to add postgres and mysql config options.

func (*WorkerApp) Description

func (a *WorkerApp) Description(description string) *WorkerApp

Description allows the user to set a description of the worker that will be shown with the help screen.

The description should also include information about what the worker expects from the NewWorker 'info' string.

func (*WorkerApp) FileOpts

func (a *WorkerApp) FileOpts() *WorkerApp

FileOpts provides file options such as aws connection info.

func (*WorkerApp) GetFileOpts

func (a *WorkerApp) GetFileOpts() *file.Options

func (*WorkerApp) Initialize

func (a *WorkerApp) Initialize()

Start is non-blocking and will perform application startup tasks such as: *Parsing and handling flags *Parsing and validating the config file *Setting config defaults

Note that start will handle application closure if there was an error during startup or a flag option was provided that asked the application to show the version, for example. So, if start is able to finish by returning, the user knows it is safe to move on.

func (*WorkerApp) Log

func (a *WorkerApp) Log(format string, v ...interface{})

Log is a wrapper around the application logger Printf method.

func (*WorkerApp) Logger

func (a *WorkerApp) Logger() *log.Logger

Logger returns a reference to the application logger.

func (*WorkerApp) MySQLDB

func (a *WorkerApp) MySQLDB() *sql.DB

MySQLDB returns the MySQL sql.DB application connection. Will be nil if called before Start() or MySQLOpts() was not called.

func (*WorkerApp) MySQLOpts

func (a *WorkerApp) MySQLOpts() *WorkerApp

MySQLOpts will parse mysql db connection options from the config toml file.

If using mysql options then a mysql db connection is made during startup. The mysql db connection is available through the MySQL() method.

MySQLOpts needs to be called before Start() to be effective.

If the user needs more than one db connection then those connection options need to be made available with the WorkerApp initialization. Note that the DBOptions struct is available to use in this way.

func (*WorkerApp) NewConsumer

func (a *WorkerApp) NewConsumer(topic, channel string) bus.Consumer

NewConsumer is a convenience method that will use the bus config information to create a new consumer instance. Can optionally provide a topic and channel on which to consume. All other bus options are the same.

func (*WorkerApp) NewProducer

func (a *WorkerApp) NewProducer() bus.Producer

NewProducer will use the bus config information to create a new producer instance.

func (*WorkerApp) PostgresDB

func (a *WorkerApp) PostgresDB() *sql.DB

PostgresDB returns the Postgres sql.DB application connection. Will be nil if called before Start() or PostgresOpts() was not called.

func (*WorkerApp) PostgresOpts

func (a *WorkerApp) PostgresOpts() *WorkerApp

PostgresOpts will parse postgres db connection options from the config toml file.

If using postgres options then a postgres db connection is made during startup. The postgres db connection is available through the Postgres() method.

PostgresOpts needs to be called before Start() to be effective.

If the user needs more than one db connection then those connection options need to be made available with the WorkerApp initialization. Note that the DBOptions struct is available to use in this way.

func (*WorkerApp) Run

func (a *WorkerApp) Run()

Run will run until the application is complete and then exit.

func (*WorkerApp) SetLogger

func (a *WorkerApp) SetLogger(lgr *log.Logger) *WorkerApp

SetLogger allows the user to override the default application logger (stdout) with a custom one.

If the provided logger is nil the logger output is discarded.

SetLogger should be called before initializing the application.

func (*WorkerApp) TaskType

func (a *WorkerApp) TaskType() string

TaskType returns the TaskType initialized with the WorkerApp.

func (*WorkerApp) Version

func (a *WorkerApp) Version(version string) *WorkerApp

Version sets the application version. The version is what is shown if the '-version' flag is specified when running the WorkerApp.

Jump to

Keyboard shortcuts

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