app

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

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

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 NewRunner

func NewRunner() *Runner

func (*Runner) HTTPServerBuilder

func (r *Runner) HTTPServerBuilder() *echo.Builder

func (*Runner) OTeLProviderBuilder added in v0.15.0

func (r *Runner) OTeLProviderBuilder() *commonOtel.Builder

func (*Runner) SetBanner added in v0.4.0

func (r *Runner) SetBanner(banner string) *Runner

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

func (r *Runner) SetTimeout(timeout time.Duration) *Runner

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 (r *Runner) WithCronTasks(cronSchedule string, t ...interface{}) *Runner

func (*Runner) WithDefaultHTTPServer

func (r *Runner) WithDefaultHTTPServer(metricNamespace string) *Runner

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

func (*Runner) WithTasks

func (r *Runner) WithTasks(t ...interface{}) *Runner

WithTasks is the way to add different tasks that will be executed asynchronously. If a task ended with no error, it won't necessarily stop the whole application. It will mainly depend on how the task is managing the context passed in parameter.

func (*Runner) WithTimerTasks added in v0.23.1

func (r *Runner) WithTimerTasks(duration time.Duration, t ...interface{}) *Runner

WithTimerTasks is the way to add different tasks that will be executed periodically at the frequency defined with the duration.

Jump to

Keyboard shortcuts

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