proxy

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SSLNone defines to run http server only
	SSLNone sslMode = iota

	// SSLStatic defines to run both https and http server. Redirect http to https
	SSLStatic

	// SSLAuto defines to run both https and http server. Redirect http to https. Https server with autocert support
	SSLAuto
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheControl added in v0.5.0

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

CacheControl sets Cache-Control response header with different ages for different mimes

func MakeCacheControl added in v0.5.0

func MakeCacheControl(cacheOpts []string) (*CacheControl, error)

MakeCacheControl creates CacheControl from the list of params. the first param represents default age and can be just a duration string (i.e. 60h) or "default:60h" all other params are mime:duration pairs, i.e. "text/html:30s"

func NewCacheControl added in v0.5.0

func NewCacheControl(defaultAge time.Duration) *CacheControl

NewCacheControl creates NewCacheControl with the default max age

func (*CacheControl) AddMime added in v0.5.0

func (c *CacheControl) AddMime(m string, d time.Duration)

AddMime sets max age for a given mime

func (*CacheControl) Middleware added in v0.5.0

func (c *CacheControl) Middleware(next http.Handler) http.Handler

Middleware checks if mime custom age set and returns it if matched to content type from resource (file) extension. fallback to default if nothing matched

type ErrorReporter added in v0.5.0

type ErrorReporter struct {
	Template string
	Nice     bool
	// contains filtered or unexported fields
}

ErrorReporter formats error with a given template Supports go-style template with {{.ErrMessage}} and {{.ErrCode}}

func (*ErrorReporter) Report added in v0.5.0

func (em *ErrorReporter) Report(w http.ResponseWriter, code int)

Report formats and sends error to ResponseWriter

type FailoverSelector added in v1.1.0

type FailoverSelector struct{}

FailoverSelector is a selector with failover, thread-safe

func (*FailoverSelector) Select added in v1.1.0

func (r *FailoverSelector) Select(_ int) int

Select returns next backend index

type Http

type Http struct {
	Matcher
	Address          string
	AssetsLocation   string
	AssetsWebRoot    string
	Assets404        string
	AssetsSPA        bool
	MaxBodySize      int64
	GzEnabled        bool
	ProxyHeaders     []string
	DropHeader       []string
	SSLConfig        SSLConfig
	Insecure         bool
	Version          string
	AccessLog        io.Writer
	StdOutEnabled    bool
	Signature        bool
	Timeouts         Timeouts
	CacheControl     MiddlewareProvider
	Metrics          MiddlewareProvider
	PluginConductor  MiddlewareProvider
	Reporter         Reporter
	LBSelector       LBSelector
	OnlyFrom         *OnlyFrom
	BasicAuthEnabled bool
	BasicAuthAllowed []string

	ThrottleSystem int
	ThrottleUser   int

	KeepHost bool
}

Http is a proxy server for both http and https

func (*Http) Run

func (h *Http) Run(ctx context.Context) error

Run the lister and request's router, activate rest server

type LBSelector added in v1.1.0

type LBSelector interface {
	Select(len int) int // return index of picked server
}

LBSelector defines load balancer strategy

type LBSelectorFunc added in v1.1.0

type LBSelectorFunc func(n int) int

LBSelectorFunc is a functional adapted for LBSelector to select backend from the list

func (LBSelectorFunc) Select added in v1.1.0

func (f LBSelectorFunc) Select(n int) int

Select returns backend index

type Matcher

type Matcher interface {
	Match(srv, src string) (res discovery.Matches)
	Servers() (servers []string)
	Mappers() (mappers []discovery.URLMapper)
	CheckHealth() (pingResult map[string]error)
}

Matcher source info (server and route) to the destination url If no match found return ok=false

type MatcherMock added in v0.8.0

type MatcherMock struct {
	// CheckHealthFunc mocks the CheckHealth method.
	CheckHealthFunc func() map[string]error

	// MappersFunc mocks the Mappers method.
	MappersFunc func() []discovery.URLMapper

	// MatchFunc mocks the Match method.
	MatchFunc func(srv string, src string) discovery.Matches

	// ServersFunc mocks the Servers method.
	ServersFunc func() []string
	// contains filtered or unexported fields
}

MatcherMock is a mock implementation of Matcher.

func TestSomethingThatUsesMatcher(t *testing.T) {

	// make and configure a mocked Matcher
	mockedMatcher := &MatcherMock{
		CheckHealthFunc: func() map[string]error {
			panic("mock out the CheckHealth method")
		},
		MappersFunc: func() []discovery.URLMapper {
			panic("mock out the Mappers method")
		},
		MatchFunc: func(srv string, src string) discovery.Matches {
			panic("mock out the Match method")
		},
		ServersFunc: func() []string {
			panic("mock out the Servers method")
		},
	}

	// use mockedMatcher in code that requires Matcher
	// and then make assertions.

}

func (*MatcherMock) CheckHealth added in v0.8.0

func (mock *MatcherMock) CheckHealth() map[string]error

CheckHealth calls CheckHealthFunc.

func (*MatcherMock) CheckHealthCalls added in v0.8.0

func (mock *MatcherMock) CheckHealthCalls() []struct {
}

CheckHealthCalls gets all the calls that were made to CheckHealth. Check the length with:

len(mockedMatcher.CheckHealthCalls())

func (*MatcherMock) Mappers added in v0.8.0

func (mock *MatcherMock) Mappers() []discovery.URLMapper

Mappers calls MappersFunc.

func (*MatcherMock) MappersCalls added in v0.8.0

func (mock *MatcherMock) MappersCalls() []struct {
}

MappersCalls gets all the calls that were made to Mappers. Check the length with:

len(mockedMatcher.MappersCalls())

func (*MatcherMock) Match added in v0.8.0

func (mock *MatcherMock) Match(srv string, src string) discovery.Matches

Match calls MatchFunc.

func (*MatcherMock) MatchCalls added in v0.8.0

func (mock *MatcherMock) MatchCalls() []struct {
	Srv string
	Src string
}

MatchCalls gets all the calls that were made to Match. Check the length with:

len(mockedMatcher.MatchCalls())

func (*MatcherMock) Servers added in v0.8.0

func (mock *MatcherMock) Servers() []string

Servers calls ServersFunc.

func (*MatcherMock) ServersCalls added in v0.8.0

func (mock *MatcherMock) ServersCalls() []struct {
}

ServersCalls gets all the calls that were made to Servers. Check the length with:

len(mockedMatcher.ServersCalls())

type MiddlewareProvider added in v0.5.0

type MiddlewareProvider interface {
	Middleware(next http.Handler) http.Handler
}

MiddlewareProvider interface defines http middleware handler

type OFLookup added in v1.1.0

type OFLookup string

OFLookup defines lookup method for source IP.

const (
	OFRemoteAddr OFLookup = "remote-addr"
	OFRealIP     OFLookup = "real-ip"
	OFForwarded  OFLookup = "forwarded"
)

enum of possible lookup methods

type OnlyFrom added in v1.1.0

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

OnlyFrom implements middleware to allow access for a limited list of source IPs.

func NewOnlyFrom added in v1.1.0

func NewOnlyFrom(lookups ...OFLookup) *OnlyFrom

NewOnlyFrom creates OnlyFrom middleware with given lookup methods.

func (*OnlyFrom) Handler added in v1.1.0

func (o *OnlyFrom) Handler(next http.Handler) http.Handler

Handler implements middleware interface.

type RandomSelector added in v1.1.0

type RandomSelector struct{}

RandomSelector is a random selector, thread-safe

func (*RandomSelector) Select added in v1.1.0

func (r *RandomSelector) Select(n int) int

Select returns random backend index

type Reporter added in v0.5.0

type Reporter interface {
	Report(w http.ResponseWriter, code int)
}

Reporter defines error reporting service

type RoundRobinSelector added in v1.1.0

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

RoundRobinSelector is a simple round-robin selector, thread-safe

func (*RoundRobinSelector) Select added in v1.1.0

func (r *RoundRobinSelector) Select(n int) int

Select returns next backend index

type SSLConfig

type SSLConfig struct {
	SSLMode       sslMode
	Cert          string
	Key           string
	ACMELocation  string
	ACMEEmail     string
	FQDNs         []string
	RedirHTTPPort int
}

SSLConfig holds all ssl params for rest server

type Timeouts added in v0.2.0

type Timeouts struct {
	// server timeouts
	ReadHeader time.Duration
	Write      time.Duration
	Idle       time.Duration
	// transport timeouts
	Dial           time.Duration
	KeepAlive      time.Duration
	IdleConn       time.Duration
	TLSHandshake   time.Duration
	ExpectContinue time.Duration
	ResponseHeader time.Duration
}

Timeouts consolidate timeouts for both server and transport

Jump to

Keyboard shortcuts

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