app

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

The package app is exposing a struct to handle the building and the managing of the different task 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()
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// BuildTime is the date when the application has been built.
	BuildTime string
	// Version is the current version of the application
	Version string
	// Commit is the ID of the commit when the application has been built
	Commit string
)

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) SetCronPeriod

func (r *Runner) SetCronPeriod(period time.Duration) *Runner

func (*Runner) SetTimeout

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

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(t ...interface{}) *Runner

WithCronTasks is the way to add different task that will be executed periodically at the same frequency. If you want to run different task with different period of time, you probably create by your own an async.TaskRunner using the method async.NewCron. In that case you certainly would prefer to use the method WithTaskRunners instead

func (*Runner) WithDefaultHTTPServer

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

func (*Runner) WithTaskRunners

func (r *Runner) WithTaskRunners(t ...async.TaskRunner) *Runner

func (*Runner) WithTasks

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

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

Jump to

Keyboard shortcuts

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