Documentation ¶
Overview ¶
Package app is exposing a struct to handle the building and the management of the different tasks coming from the package async. This should be used in the main package only.
A quite straightforward usage of this package is when you are implementing an HTTP API and want to expose it. In that case you can use the following example:
package main import ( "github.com/perses/commun/app" ) func main() { // create your api api := newAPI() // then use the app package to start it properly runner := app.NewRunner().WithDefaultHTTPServer("your_api_name") runner.HTTPServerBuilder().APIRegistration(api) // start the application runner.Start() }
You can also add custom tasks to the runner using WithTasks :
// Run all the tasks runner := app.NewRunner(). WithTasks(myTask1, myTask2). WithDefaultServerTask(prometheusNamespace) runner.Start()
Index ¶
- type Runner
- func (r *Runner) HTTPServerBuilder() *echo.Builder
- func (r *Runner) OTeLProviderBuilder() *commonOtel.Builder
- func (r *Runner) SetBanner(banner string) *Runner
- func (r *Runner) SetTimeout(timeout time.Duration) *Runner
- func (r *Runner) Start()
- func (r *Runner) WithCronTasks(cronSchedule string, t ...interface{}) *Runner
- func (r *Runner) WithDefaultHTTPServer(metricNamespace string) *Runner
- func (r *Runner) WithDefaultHTTPServerAndPrometheusRegisterer(metricNamespace string, registerer prometheus.Registerer, ...) *Runner
- func (r *Runner) WithTaskHelpers(t ...taskhelper.Helper) *Runner
- func (r *Runner) WithTasks(t ...interface{}) *Runner
- func (r *Runner) WithTimerTasks(duration time.Duration, t ...interface{}) *Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) HTTPServerBuilder ¶
func (*Runner) OTeLProviderBuilder ¶ added in v0.15.0
func (r *Runner) OTeLProviderBuilder() *commonOtel.Builder
func (*Runner) SetBanner ¶ added in v0.4.0
SetBanner is setting a string (ideally the logo of the project) that would be printed when the runner is started. Additionally, you can also print the Version, the BuildTime and the Commit. You just have to add '%s' in your banner where you want to print each information (one '%s' per additional information). If set, then the main header won't be printed. The main header is printing the Version, the Commit and the BuildTime.
func (*Runner) SetTimeout ¶
SetTimeout is setting the time to wait before killing the application once it received a cancellation order.
func (*Runner) Start ¶
func (r *Runner) Start()
Start will start the application. It is a blocking method and will give back the end once every tasks handled are done.
func (*Runner) WithCronTasks ¶
func (*Runner) WithDefaultHTTPServer ¶
func (*Runner) WithDefaultHTTPServerAndPrometheusRegisterer ¶ added in v0.24.0
func (r *Runner) WithDefaultHTTPServerAndPrometheusRegisterer(metricNamespace string, registerer prometheus.Registerer, gatherer prometheus.Gatherer) *Runner
WithDefaultHTTPServerAndPrometheusRegisterer is here to create a default HTTP server with already the metrics API setup. Usually you will use it as follows:
promRegistry := prometheus.NewRegistry() app.NewRunner().WithDefaultHTTPServerAndPrometheusRegisterer(metricNamespace, promRegistry, promRegistry)
func (*Runner) WithTaskHelpers ¶ added in v0.5.0
func (r *Runner) WithTaskHelpers(t ...taskhelper.Helper) *Runner