targets

package
v0.0.0-...-e64142b Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Protocol and port maps
	ProtocolPorts = map[string]int{
		"http":   80,
		"ssh":    22,
		"telnet": 23,
		"smtp":   25,
		"dns":    53,
		"ntp":    123,
		"ldap":   389,
		"https":  443,
		"ldaps":  636,
	}
	ProtocolTransports = map[string][]string{
		"tcp":    []string{"tcp"},
		"udp":    []string{"udp"},
		"http":   []string{"tcp"},
		"telnet": []string{"tcp"},
		"smtp":   []string{"tcp"},
		"dns":    []string{"udp", "tcp"},
		"ntp":    []string{"udp"},
		"ldap":   []string{"tcp"},
		"https":  []string{"tcp"},
		"ldaps":  []string{"tcp"},
	}

	// Errors
	ErrMissingProtocol = errors.New("Target is missing protocol")
	ErrUnknownProtocol = errors.New("Unknown network protocol")
)

Functions

func GetPort

func GetPort(protocol string) int

GetPort returns the common port number for the given application protocol string.

func GetProtocol

func GetProtocol(port int) string

GetProtocol returns the common application protocol string for the given port number.

func GetTransport

func GetTransport(protocol string) []string

GetTransport returns the common transport protocols for the given application protocol string.

func IsTLS

func IsTLS(protocol string) bool

IsTLS returns true if the given protocol uses SSL/TLS; I.E. HTTPS.

Types

type Target

type Target interface {
	// Get returns the value for the given key name of  the target's
	// attribute. Keys include:
	//   - alive
	//   - host
	//   - port
	//   - protocol
	//   - type
	Get(key string) string

	// IsAlive returns true if the target is set alive.
	IsAlive() bool

	// IsAvailable tries to dial the target with the given timeout and
	// returns true if the connection succeeded.
	IsAvailable(to time.Duration) bool

	// SetAlive sets the alive attribute of the target.
	SetAlive(v bool)

	// Summary returns a comma-separated string of key-value pairs of the
	// target's attributes.
	Summary() string

	// URL returns a URL formatted string of the target.
	// ("<scheme>://<host>[:<port>]")
	URL() string
}

Target represents an interface to a load balancer target.

func NewServiceTarget

func NewServiceTarget(target *url.URL) Target

NewServiceTarget returns a new service target for the given URL.

func NewTarget

func NewTarget(host string, port int, protocol string) Target

NewTarget returns a new Target for the given parameters.

type TargetGroup

type TargetGroup struct {
	Name     string     // Group name
	Protocol string     // Common group protocol
	Rule     rules.Rule // Request rule
	Targets  []Target   // List of targets
}

TargetGroup represents a group of targets.

func NewTargetGroup

func NewTargetGroup(name, protocol string, rule rules.Rule, target ...Target) *TargetGroup

NewTargetGroup returns a new TargetGroup.

func (*TargetGroup) AddServiceTarget

func (tg *TargetGroup) AddServiceTarget(target *url.URL)

AddServiceTarget adds a new target as a service via a given URL.

func (*TargetGroup) AddTarget

func (tg *TargetGroup) AddTarget(host string, port int)

AddTarget adds a new target via a given host and port.

type TargetType

type TargetType uint32

TargetType represents a type of load balancer target type.

const (
	// Target types
	TargetTypeIP TargetType = iota + 1
	TargetTypeDomain
)

func (TargetType) String

func (tt TargetType) String() string

String returns the string representation of the target type.

Jump to

Keyboard shortcuts

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