server

package module
v1.0.48 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: Apache-2.0 Imports: 2 Imported by: 9

Documentation

Overview

The `server` package implements a generic server, which runs multiple tasks until any single task is completed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	Context() context.Context // Returns the context of the emitted event from the source
	Key() any                 // Returns the key (or "type") of the event. Returns nil if an error event
	Value() any               // Returns the value of the event. Returns an error if an error event
	Error() error             // Returns the error or nil if not an error event

	// Emit an event on a channel. If the channel is buffered, returns false if the
	// event could not be sent (buffered channel is full). Blocks if an unbuferred channel.
	// Returns false if an error occured.
	Emit(chan<- Event) bool
}

Event encapsulates a transmitted message with key, value pair. It can also encapsulate an error.

type EventReceiver added in v1.0.48

type EventReceiver interface {
	Rcv(context.Context, func(Event) error, ...EventSource) error
}

EventReceiver receives and processes events from one or more sources

type EventSource added in v1.0.48

type EventSource interface {
	Sub() <-chan Event
	Unsub(<-chan Event)
}

EventSource is the interface for subscribing and unsubscribing from events

type Plugin

type Plugin interface {
	Name() string                                // Return the name of the task. This should be unique amongst all registered plugins
	Label() string                               // Return the label for the task. This should be unique amongst all plugins with the same name
	New(context.Context, Provider) (Task, error) // Create a new task with provider of other tasks
}

Plugin creates a task from a configuration

type Provider

type Provider interface {
	Task
	plugin.Log

	// Create a new task from a plugin and return it. This should only
	// be called during the initialisation phase of the provider, not once
	// the provider is running.
	New(context.Context, Plugin) (Task, error)

	// Return a task with name and label. Two arguments are required if the first argument is
	// the task name and the second is the task label. Returns nil if there isn't exactly one
	// task to return.
	Get(...string) Task
}

Provider runs many tasks simultaneously. It subscribes to events from the tasks and emits them on its own event channel.

type Task added in v1.0.48

type Task interface {
	EventSource

	// Run the task until the context is cancelled, and return any errors
	Run(context.Context) error
}

Task is a long-running task which can be a source of events and errors

Directories

Path Synopsis
cmd
server command
pkg
config/json
The `json` package provides a decoder for JSON configuration files.
The `json` package provides a decoder for JSON configuration files.
context
The `context` package provides functions to embed parameters within a context object, and also functions to create contexts.
The `context` package provides functions to embed parameters within a context object, and also functions to create contexts.
dnsregister
The `dnsregister` task implements a server which can register DNS entries
The `dnsregister` task implements a server which can register DNS entries
event
The event package implements events, an event source and an event receiver.
The event package implements events, an event source and an event receiver.
httpserver
The `httpserver` task implements a server which can serve requests over HTTP, HTTPS and FCGI
The `httpserver` task implements a server which can serve requests over HTTP, HTTPS and FCGI
httpserver/fcgi
Package fcgi implements the FastCGI protocol.
Package fcgi implements the FastCGI protocol.
log
Package `log` implements a simple logger that can be used to log messages
Package `log` implements a simple logger that can be used to log messages
router
router package implements a http.Handler and the ability to register routes on a gateway
router package implements a http.Handler and the ability to register routes on a gateway
task
package `task` implements a generic task runner, which can be a source of events
package `task` implements a generic task runner, which can be a source of events
types
The `types` package implements variable types which can be used in configurations.
The `types` package implements variable types which can be used in configurations.
dnsregister command

Jump to

Keyboard shortcuts

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