echo

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: 14 Imported by: 2

Documentation

Overview

Package echo is exposing a struct to handle the building and the management of the different tasks coming from the async package. This should be used in the main package only. This package provides a way to build an echo server easily (see https://echo.labstack.com), with a prometheus metrics endpoint and that relies on logrus for logging (see https://github.com/sirupsen/logrus).

Please favor the usage of [app](../app) package to run an echo web server.

Features

- Build and run an echo server with a "/metrics" endpoint.

- Register an API.

- Register a Middleware.

Usage

Instantiate a simple server task :

package my_package

import (
    "context"

    "github.com/perses/common/echo"
)

const (
    // The address on which the server is listening.
    addr = ":8080"
    metricNamespace = "my_project"
)

func main() {
    serverTask, err := echo.NewBuilder(addr).
            APIRegistration(echo.NewMetricsAPI(true)).
            MetricNamespace(metricNamespace).
            Build()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder(addr string) *Builder

func (*Builder) APIRegistration

func (b *Builder) APIRegistration(api Register) *Builder

APIRegistration must be used to register an HTTP API.

func (*Builder) ActivatePprof added in v0.7.0

func (b *Builder) ActivatePprof(activate bool) *Builder

func (*Builder) Build

func (b *Builder) Build() (async.Task, error)

func (*Builder) BuildHandler added in v0.18.0

func (b *Builder) BuildHandler() (http.Handler, error)

BuildHandler is creating an http Handler based on the different configuration and attribute set. It can be useful to have it when you want to use the method httptest.NewServer for testing purpose, and you want to have the same setup as the actual http server.

func (*Builder) GzipSkipper added in v0.21.0

func (b *Builder) GzipSkipper(skipper middleware.Skipper) *Builder

GzipSkipper can be used to provide a function that will tell when to skip the gzip compression. It can be used to avoid gzip to certain URL(s). The Gzip compression is activated on every URL registered in echo when using the default middleware. If you don't use the default middleware, then there is no point of using this method.

func (*Builder) MetricNamespace

func (b *Builder) MetricNamespace(namespace string) *Builder

MetricNamespace is modifying the namespace that will be used next ot prefix every metrics exposed

func (*Builder) Middleware

func (b *Builder) Middleware(mdw echo.MiddlewareFunc) *Builder

Middleware is adding the provided middleware into the Builder Order matters, add the middleware in the order you would like to see them started.

func (*Builder) OverrideDefaultMiddleware

func (b *Builder) OverrideDefaultMiddleware(override bool) *Builder

OverrideDefaultMiddleware is setting a flag that will tell if the Builder needs to override the default list of middleware considered by the one provided by the method Middleware. In case the flag is set at false, then the middleware provided by the user will be appended to the default list. Note that the default list is always executed at the beginning (a.k.a, the default middleware will be executed before yours).

func (*Builder) PrometheusRegisterer added in v0.19.0

func (b *Builder) PrometheusRegisterer(r prometheus.Registerer) *Builder

PrometheusRegisterer will set a new metric registry for Prometheus, so it won't use the default one. That can be useful for testing purpose since you can't register in the same go instance the same metrics multiple times.

type Register

type Register interface {
	RegisterRoute(e *echo.Echo)
}

func NewMetricsAPI

func NewMetricsAPI(disableCompression bool, r prometheus.Registerer, gatherer prometheus.Gatherer) Register

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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