bootstrap

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 22 Imported by: 30

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"`
	Serializable bool   `toml:"serializable" comment:"set isolation level to serializable, required for proper writing to database" commented:"true"`
	SSLMode      string `toml:"sslmode" comment:"default is disable, use require for ssl"`
	SSLCert      string `toml:"sslcert"`
	SSLKey       string `toml:"sslkey"`
	SSLRootcert  string `toml:"sslrootcert"`
}

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 Info added in v0.2.0

type Info struct {
	AppName       string             `json:"app_name"`
	Version       string             `json:"version"`
	LauncherStats task.LauncherStats `json:"launcher,omitempty"`
	ProducerStats *info.Producer     `json:"producer,omitempty"`
	ConsumerStats *info.Consumer     `json:"consumer,omitempty"`
}

type NewRunner added in v0.2.0

type NewRunner func(*TaskMaster) Runner

type NilValidator

type NilValidator struct{}

NilValidator satisfies the Validator interface but does nothing.

func (*NilValidator) Validate

func (v *NilValidator) Validate() error

type Runner added in v0.2.0

type Runner interface {
	Run(ctx context.Context) error
	Info() interface{}
}

type TaskMaster added in v0.2.0

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

func NewTaskMaster added in v0.2.0

func NewTaskMaster(appName string, initFn NewRunner, options Validator) *TaskMaster

NewTaskMaster will create a new taskmaster bootstrap application. *appName: defines the taskmaster name; acts as a name for identification and easy-of-use (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 (*TaskMaster) AppName added in v0.2.0

func (tm *TaskMaster) AppName() string

AppName returns the AppName initialized with the WorkerApp.

func (*TaskMaster) AppOpt added in v0.2.0

func (tm *TaskMaster) AppOpt() interface{}

func (*TaskMaster) Description added in v0.2.0

func (tm *TaskMaster) Description(description string) *TaskMaster

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 (*TaskMaster) FileOpts added in v0.2.0

func (tm *TaskMaster) FileOpts() *TaskMaster

FileOpts provides file options such as aws connection info.

func (*TaskMaster) GetBusOpts added in v0.6.1

func (tm *TaskMaster) GetBusOpts() *bus.Options

func (*TaskMaster) GetFileOpts added in v0.2.0

func (tm *TaskMaster) GetFileOpts() *file.Options

func (*TaskMaster) HandleRequest added in v0.2.0

func (tm *TaskMaster) HandleRequest(w http.ResponseWriter, r *http.Request)

HandleRequest is a simple http handler function that takes the compiled status functions that are called and the results marshaled to return as the body of the response

func (*TaskMaster) HttpPort added in v0.2.0

func (tm *TaskMaster) HttpPort() int

HttpPort gets the application http port for requesting a heath check on the application itself.

func (*TaskMaster) Initialize added in v0.2.0

func (tm *TaskMaster) Initialize() *TaskMaster

Initialize 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 (*TaskMaster) Log added in v0.2.0

func (tm *TaskMaster) Log(format string, v ...interface{})

Log is a wrapper around the application logger Printf method.

func (*TaskMaster) Logger added in v0.2.0

func (tm *TaskMaster) Logger() *log.Logger

Logger returns a reference to the application logger.

func (*TaskMaster) MySQLDB added in v0.2.0

func (tm *TaskMaster) MySQLDB() *sql.DB

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

func (*TaskMaster) MySQLOpts added in v0.2.0

func (tm *TaskMaster) MySQLOpts() *TaskMaster

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 (*TaskMaster) NewConsumer added in v0.2.0

func (tm *TaskMaster) NewConsumer() 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 (*TaskMaster) NewProducer added in v0.2.0

func (tm *TaskMaster) NewProducer() bus.Producer

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

func (*TaskMaster) PostgresDB added in v0.2.0

func (tm *TaskMaster) PostgresDB() *sql.DB

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

func (*TaskMaster) PostgresOpts added in v0.2.0

func (tm *TaskMaster) PostgresOpts() *TaskMaster

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 (*TaskMaster) Run added in v0.2.0

func (tm *TaskMaster) Run()

Run until the application is complete and then exit.

func (*TaskMaster) SetHandler added in v0.6.0

func (tm *TaskMaster) SetHandler(fn func(http.ResponseWriter, *http.Request))

SetHandler will overwrite the current HandleRequest function on root requests

func (*TaskMaster) SetLogger added in v0.2.0

func (tm *TaskMaster) SetLogger(lgr *log.Logger) *TaskMaster

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 (*TaskMaster) Version added in v0.2.0

func (tm *TaskMaster) Version(version string) *TaskMaster

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

type Utility added in v0.2.0

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

func NewUtility added in v0.2.0

func NewUtility(name string, config interface{}) *Utility

func (*Utility) AddInfo added in v0.3.0

func (u *Utility) AddInfo(info func() interface{}, port int) *Utility

func (*Utility) Description added in v0.2.0

func (u *Utility) Description(description string) *Utility

func (*Utility) Initialize added in v0.2.0

func (u *Utility) Initialize()

func (*Utility) Version added in v0.2.0

func (u *Utility) Version(version string) *Utility

type Validator

type Validator interface {
	Validate() error
}

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

type Worker added in v0.2.0

type Worker struct {
	Info // info stats on various worker types
	// contains filtered or unexported fields
}

func NewWorkerApp

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

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 Worker already provides bus and launcher config options and the user
can request to add postgres and mysql config options.

func (*Worker) Description added in v0.2.0

func (w *Worker) Description(description string) *Worker

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 (*Worker) FileOpts added in v0.2.0

func (w *Worker) FileOpts() *Worker

FileOpts provides file options such as aws connection info.

func (*Worker) GetFileOpts added in v0.2.0

func (w *Worker) GetFileOpts() *file.Options

func (*Worker) HandleRequest added in v0.2.0

func (w *Worker) HandleRequest(wr http.ResponseWriter, r *http.Request)

HandleRequest is a simple http handler function that takes the compiled status functions that are called and the results marshaled to return as the body of the response

func (*Worker) HttpPort added in v0.2.0

func (w *Worker) HttpPort() int

HttpPort gets the application http port for requesting a heath check on the application itself. If the port is not provided The port should alwasy be provided

func (*Worker) InfoStats added in v0.2.0

func (w *Worker) InfoStats() Info

InfoStats for the Worker app

func (*Worker) Initialize added in v0.2.0

func (w *Worker) Initialize() *Worker

Initialize 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 Initialize 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 Initialize is able to finish by returning, the user knows it is safe to move on.

func (*Worker) Log added in v0.2.0

func (w *Worker) Log(format string, v ...interface{})

Log is a wrapper around the application logger Printf method.

func (*Worker) Logger added in v0.2.0

func (w *Worker) Logger() *log.Logger

Logger returns a reference to the application logger.

func (*Worker) MySQLDB added in v0.2.0

func (w *Worker) MySQLDB() *sql.DB

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

func (*Worker) MySQLOpts added in v0.2.0

func (w *Worker) MySQLOpts() *Worker

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 Worker initialization. Note that the DBOptions struct is available to use in this way.

func (*Worker) NewConsumer added in v0.2.0

func (w *Worker) 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 (*Worker) NewProducer added in v0.2.0

func (w *Worker) NewProducer() bus.Producer

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

func (*Worker) PostgresDB added in v0.2.0

func (w *Worker) PostgresDB() *sql.DB

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

func (*Worker) PostgresOpts added in v0.2.0

func (w *Worker) PostgresOpts() *Worker

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 Worker initialization. Note that the DBOptions struct is available to use in this way.

func (*Worker) Run added in v0.2.0

func (w *Worker) Run()

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

func (*Worker) SetLogger added in v0.2.0

func (w *Worker) SetLogger(lgr *log.Logger) *Worker

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 (*Worker) TaskType added in v0.2.0

func (w *Worker) TaskType() string

TaskType returns the TaskType initialized with the Worker.

func (*Worker) Version added in v0.2.0

func (w *Worker) Version(version string) *Worker

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

Jump to

Keyboard shortcuts

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