orch

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package orch provides some orchestration functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// BuildStaticServer is used to customize the building of the static server,
	// which is used by the default discovery builder.
	//
	// Default: use http/endpoint.New to build it.
	BuildStaticServer func(server Server) (loadbalancer.Endpoint, error)

	// BuildDiscovery builds a discovery by the config.
	BuildDiscovery func(upid string, discovery Discovery) (loadbalancer.Discovery, error)
)
View Source
var BuildHttpRouteResponser func(r HttpRoute) (core.Responser, error)

BuildHttpRouteResponser is used to build a responser of the http route.

If not set or return nil, use core.StdResponse instead.

Default: nil

Functions

func BuildStaticServers

func BuildStaticServers(servers []Server) (loadbalancer.Endpoints, error)

BuildStaticServers builds a set of servers, which use BuildStaticServer to build each server.

func CompareServer

func CompareServer(a, b Server) int

CompareServer compares the two servers to sort a set of servers.

-1 if a <  b
 0 if a == b
 1 if a >  b

func GetConfig

func GetConfig(v any) any

GetConfig tries to assert the input argument v to the interface { Config() any }, calls it and returns the result if successfully; or, returns nil.

Types

type Discovery

type Discovery struct {
	Static *StaticDiscovery `json:"static,omitempty" yaml:"static,omitempty"`
}

Discovery is the configuration of the upstream server discovery.

type HttpMatcher

type HttpMatcher struct {
	// Exact(www.example.com) or Wildcard(*.example.com)
	//
	// OR Match
	Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`

	// Exact OR Match
	Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`

	// Exact OR Match
	Paths        []string `json:"paths,omitempty" yaml:"paths,omitempty"`
	PathPrefixes []string `json:"pathPrefixes,omitempty" yaml:"pathPrefixes,omitempty"`

	// Exact Match
	Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
	Queries map[string]string `json:"queries,omitempty" yaml:"queries,omitempty"`

	// IPv4CIDR or IPv6CIDR
	ClientIps []string `json:"clientIps,omitempty" yaml:"clientIps,omitempty"`
	ServerIps []string `json:"serverIps,omitempty" yaml:"serverIps,omitempty"`
}

HttpRouteMatcher is the configuraiton of a route matcher.

func (HttpMatcher) Build

func (m HttpMatcher) Build() (matcher.Matcher, error)

Build builds the matcher.

type HttpMatchers

type HttpMatchers []HttpMatcher

HttpMatchers represents a set of http matchers.

func (HttpMatchers) Build

func (ms HttpMatchers) Build() (m matcher.Matcher, err error)

Build builds a set of matchers to a route matcher.

type HttpRoute

type HttpRoute struct {
	// Required
	Id       string       `json:"id" yaml:"id"`
	Upstream string       `json:"upstream" yaml:"upstream"`
	Matchers HttpMatchers `json:"matchers" yaml:"matchers"`

	// Optional
	Protect  bool `json:"protect,omitempty" yaml:"protect,omitempty"`
	Priority int  `json:"priority,omitempty" yaml:"priority,omitempty"`

	RequestTimeout time.Duration `json:"requestTimeout,omitempty" yaml:"requestTimeout,omitempty"`
	ForwardTimeout time.Duration `json:"forwardTimeout,omitempty" yaml:"forwardTimeout,omitempty"`

	Middlewares      Middlewares `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
	MiddlewareGroups []string    `json:"middlewareGroups,omitempty" yaml:"middlewareGroups,omitempty"`

	// Addon information.
	Handler any `json:"handler,omitempty" yaml:"handler,omitempty"`
	Extra   any `json:"extra,omitempty" yaml:"extra,omitempty"`
}

HttpRoute is a http route configuration.

func DiffHttpRoutes

func DiffHttpRoutes(news, olds []HttpRoute) (adds, dels []HttpRoute)

DiffHttpRoutes compares the difference between new and old routes, and reutrns the added and deleted routes.

func (HttpRoute) Build

func (r HttpRoute) Build() (router.Route, error)

Build builds the runtime route by the route config.

type Middleware

type Middleware struct {
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	Conf any    `json:"conf,omitempty" yaml:"conf,omitempty"`
}

Middleware represents a middleware.

func (Middleware) HttpBuild

func (m Middleware) HttpBuild() (middleware.Middleware, error)

HttpBuild builds the middleware based on http.

type MiddlewareGroup

type MiddlewareGroup struct {
	// Optional, One of "tcp", "http"
	//
	// Default: http
	Type string `json:"type,omitempty" yaml:"type,omitempty"`

	// Required
	Name        string      `json:"name,omitempty" yaml:"name,omitempty"`
	Middlewares Middlewares `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
}

MiddlewareGroup is the configuration of a middleare group.

func DiffMiddlewareGroups

func DiffMiddlewareGroups(news, olds []MiddlewareGroup) (adds, dels []MiddlewareGroup)

DiffMiddlewareGroups compares the difference between new and old middleware groups, and returns the changed middleware groups.

func (MiddlewareGroup) Equal

func (g MiddlewareGroup) Equal(other MiddlewareGroup) bool

Equal reports whether it is equal to other middlewares.

func (MiddlewareGroup) HttpBuild

func (g MiddlewareGroup) HttpBuild() (*middleware.Group, error)

HttpBuild builds a middleware group based on http.

type Middlewares

type Middlewares []Middleware

Middlewares represents a set of middlewares.

type Retry

type Retry struct {
	Number   int           `json:"number,omitempty" yaml:"number,omitempty"`     // <0: disabled
	Interval time.Duration `json:"interval,omitempty" yaml:"interval,omitempty"` // [0, +∞), Unit: ms
}

Retry is a retry configuration.

type Server

type Server struct {
	Host   string `json:"host,omitempty" yaml:"host,omitempty"`
	Port   uint16 `json:"port,omitempty" yaml:"port,omitempty"`
	Weight int    `json:"weight,omitempty" yaml:"weight,omitempty"`
}

Server is the configuraiton of an upstream server.

type StaticDiscovery

type StaticDiscovery struct {
	Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
}

StaticDiscovery is the configuration of the static upstream server discovery.

type Upstream

type Upstream struct {
	// Required
	Id        string    `json:"id" yaml:"id"`
	Discovery Discovery `json:"discovery" yaml:"discovery"`

	// Optional, Default: 0
	Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`

	// Optional
	Policy string `json:"policy,omitempty" yaml:"policy,omitempty"` // Default: roundrobin
	Retry  Retry  `json:"retry,omitempty" yaml:"retry,omitempty"`

	// Optional
	Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"` // "http(default)", "https", "tcp", "tls"
	Host   string `json:"host,omitempty" yaml:"host,omitempty"`     // "$client"(default), "$server", "xxx"
	Path   string `json:"path,omitempty" yaml:"path,omitempty"`
}

Upstream is an upstream configuraiton.

func DiffUpstreams

func DiffUpstreams(news, olds []Upstream) (adds, dels []Upstream)

DiffUpstreams compares the difference between new and old upstreams, and reutrns the added and deleted upstreams.

NOTICE: adds also contains the existed but changed upstreams.

func (Upstream) Build

func (up Upstream) Build() (*upstream.Upstream, error)

Build builds an upstream by the config.

func (Upstream) ForwardPolicy

func (u Upstream) ForwardPolicy() string

ForwardPolicy returns the normalized forwarding policy.

Directories

Path Synopsis
Package updater provides a common mechanism to updates the runtime from the synchronized configurations.
Package updater provides a common mechanism to updates the runtime from the synchronized configurations.

Jump to

Keyboard shortcuts

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