api

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package api implements a type used for creating the Benthos HTTP API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Address        string `json:"address" yaml:"address"`
	ReadTimeoutMS  int    `json:"read_timeout_ms" yaml:"read_timeout_ms"`
	RootPath       string `json:"root_path" yaml:"root_path"`
	DebugEndpoints bool   `json:"debug_endpoints" yaml:"debug_endpoints"`
}

Config contains the configuration fields for the Benthos API.

func NewConfig

func NewConfig() Config

NewConfig creates a new API config with default values.

type Dynamic

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

Dynamic is a type for exposing CRUD operations on dynamic broker configurations as an HTTP interface. Events can be registered for listening to configuration changes, and these events should be forwarded to the dynamic broker.

func NewDynamic

func NewDynamic() *Dynamic

NewDynamic creates a new Dynamic API type.

func (*Dynamic) HandleCRUD

func (d *Dynamic) HandleCRUD(w http.ResponseWriter, r *http.Request)

HandleCRUD is an http.HandleFunc for performing CRUD operations on dynamic components by their ids.

func (*Dynamic) HandleList

func (d *Dynamic) HandleList(w http.ResponseWriter, r *http.Request)

HandleList is an http.HandleFunc for returning maps of active dynamic components by their id to uptime.

func (*Dynamic) OnDelete

func (d *Dynamic) OnDelete(onDelete func(id string) error)

OnDelete registers a func to handle CRUD events where a request wants to remove a dynamic configuration. An error should be returned if the component failed to close.

func (*Dynamic) OnUpdate

func (d *Dynamic) OnUpdate(onUpdate func(id string, conf []byte) error)

OnUpdate registers a func to handle CRUD events where a request wants to set a new value for a dynamic configuration. An error should be returned if the configuration is invalid or the component failed.

func (*Dynamic) Started

func (d *Dynamic) Started(id string, config []byte)

Started should be called whenever an active dynamic component has started with a new configuration. A normalised form of the configuration should be provided and will be delivered to clients that query the component contents.

func (*Dynamic) Stopped

func (d *Dynamic) Stopped(id string)

Stopped should be called whenever an active dynamic component has closed, whether by naturally winding down or from a request.

type Type

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

Type implements the Benthos HTTP API.

func New

func New(
	version string,
	dateBuilt string,
	conf Config,
	wholeConf interface{},
	log log.Modular,
	stats metrics.Type,
) *Type

New creates a new Benthos HTTP API.

func (*Type) ListenAndServe

func (t *Type) ListenAndServe() error

ListenAndServe launches the API and blocks until the server closes or fails.

func (*Type) RegisterEndpoint

func (t *Type) RegisterEndpoint(path, desc string, handler http.HandlerFunc)

RegisterEndpoint registers a http.HandlerFunc under a path with a description that will be displayed under the /endpoints path.

func (*Type) Shutdown

func (t *Type) Shutdown(ctx context.Context) error

Shutdown attempts to close the http server.

Jump to

Keyboard shortcuts

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