services

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package services provides a way to define services that can be proxied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(services map[string]*Service) http.Handler

Handler returns a http.Handler that proxies requests to services, redirecting to TLS if applicable.

func LaunchHealthChecks

func LaunchHealthChecks(services map[string]*Service)

LaunchHealthChecks starts the health checks for all services.

func TLSHandler

func TLSHandler(services map[string]*Service) http.Handler

TLSHandler returns a http.Handler that proxies requests to services with TLS enabled.

Types

type Container

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

Container is a service that is running in a Docker container.

func NewContainer

func NewContainer(name string, network string, port uint16, docker dockerapi.Docker) *Container

NewContainer creates a new service from a docker container.

func (*Container) Route

func (c *Container) Route(_ http.ResponseWriter, _ *http.Request) (*url.URL, error)

Route iterates through the list of containers and returns the remote of the matching container by name.

type Failover

type Failover struct{}

Failover is a failover selection strategy.

func (*Failover) Select

func (f *Failover) Select(services []*Service, _ *http.Request) int

Select returns the index of the first service that is healthy.

type LoadBalancer

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

LoadBalancer is a service that load balances between other services.

func NewLoadBalancer

func NewLoadBalancer(host string, strategy Strategy, persistent bool, services []*Service) *LoadBalancer

NewLoadBalancer creates a new load balancer service.

func (*LoadBalancer) Route

func (l *LoadBalancer) Route(w http.ResponseWriter, r *http.Request) (*url.URL, error)

Route returns the remote URL of the next service in the load balancer.

type Random

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

Random is a random selection strategy.

func (*Random) Select

func (r *Random) Select(services []*Service, _ *http.Request) int

Select returns the index of the next service to use using a random strategy.

type Redirect

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

Redirect is a service that redirects to a remote URL.

func NewRedirect

func NewRedirect(remote url.URL) *Redirect

NewRedirect creates a new Redirect service.

func (*Redirect) Route

func (r *Redirect) Route(_ http.ResponseWriter, _ *http.Request) (*url.URL, error)

Route redirects to the remote URL.

type RoundRobin

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

RoundRobin is a round-robin selection strategy.

func (*RoundRobin) Select

func (r *RoundRobin) Select(services []*Service, _ *http.Request) int

Select returns the index of the next service to use using a round-robin strategy.

type Router

type Router interface {
	Route(http.ResponseWriter, *http.Request) (*url.URL, error)
}

Router is something that can route a request to a service.

type Service

type Service struct {
	TLS         bool
	Middlewares []middlewares.Middleware
	Health      health.Checker

	Router Router
}

Service is a service that can be proxied.

type Strategy

type Strategy interface {
	// Select returns the index of the next service to use.
	Select([]*Service, *http.Request) int
}

Strategy defines the interface for a load balancer selection strategy.

func NewStrategy

func NewStrategy(strategy string) (Strategy, error)

NewStrategy converts a string to a Strategy. If the string is empty, the default strategy RoundRobin is used.

Directories

Path Synopsis
Package health provides utilitis to check the health of a service at a regular interval.
Package health provides utilitis to check the health of a service at a regular interval.

Jump to

Keyboard shortcuts

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