proxy

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: MIT Imports: 25 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 Http

type Http struct {
	Matcher
	Address         string
	AssetsLocation  string
	AssetsWebRoot   string
	AssetsSPA       bool
	MaxBodySize     int64
	GzEnabled       bool
	ProxyHeaders    []string
	SSLConfig       SSLConfig
	Version         string
	AccessLog       io.Writer
	StdOutEnabled   bool
	Signature       bool
	Timeouts        Timeouts
	CacheControl    MiddlewareProvider
	Metrics         MiddlewareProvider
	PluginConductor MiddlewareProvider
	Reporter        Reporter
	LBSelector      func(len int) int
}

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 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 Reporter added in v0.5.0

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

Reporter defines error reporting service

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