models

package
v0.0.0-...-504ad5f Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAddrNotFound = errors.New("Address not found")

ErrAddrNotFound address not found

View Source
var RegexpStore = NewRegexStore()

RegexpStore store regexes

Functions

func CreateDefaultConfig

func CreateDefaultConfig(file, defaultPath string) (bool, error)

CreateDefaultConfig creates the default config file

func CreateExampleRoute

func CreateExampleRoute(file string) error

CreateExampleRoute creates an example route

Types

type Config

type Config struct {
	Server          ServerConfig `toml:"Server"`
	ListenAddresses []ListenAddress
	RouteFiles      []string
}

Config configuration file

func InitConfig

func InitConfig(file, defaultPath string) *Config

InitConfig the config

func ReadConfig

func ReadConfig(file string) (*Config, error)

ReadConfig read the config file

func (Config) GetAddress

func (config Config) GetAddress(sAddress string) *ListenAddress

GetAddress gets address from config

func (Config) GetPreferredSSLAddress

func (config Config) GetPreferredSSLAddress() *ListenAddress

GetPreferredSSLAddress returns preferred SSL address

func (*Config) LoadRoutes

func (config *Config) LoadRoutes() ([]Route, error)

LoadRoutes loads the routes specified in config

type ConfigDuration

type ConfigDuration time.Duration

ConfigDuration duration for config

func (ConfigDuration) MarshalText

func (d ConfigDuration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*ConfigDuration) UnmarshalText

func (d *ConfigDuration) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type InterfaceTask

type InterfaceTask string

InterfaceTask task for an Address interface

const (
	HTTPRedirectTask InterfaceTask = "httpredirect"
	ProxyTask        InterfaceTask = "proxy"
)

...

type ListenAddress

type ListenAddress struct {
	Address             string
	SSL                 bool
	Task                InterfaceTask
	TaskData            TaskData
	IsRedirectInterface bool `toml:"-"`
}

ListenAddress config for ports

func (ListenAddress) GetAddress

func (address ListenAddress) GetAddress() string

GetAddress returns address of a listenAddress

func (ListenAddress) GetPort

func (address ListenAddress) GetPort() string

GetPort returns port of address

func (*ListenAddress) GetTask

func (address *ListenAddress) GetTask() InterfaceTask

GetTask gets task from AddressInterface. If not set, return Default task

func (*ListenAddress) Init

func (address *ListenAddress) Init()

Init inits a listenAddress

type RedirectData

type RedirectData struct {
	Body     string
	HTTPCode int
}

RedirectData data for interface Task to redirect

func (RedirectData) GetBody

func (redirectData RedirectData) GetBody() string

GetBody returns body. If empty return default body

func (RedirectData) GetHTTPCode

func (redirectData RedirectData) GetHTTPCode() int

GetHTTPCode returns body. If empty return default body

type RegexStore

type RegexStore struct {
	Store map[string]*regexp.Regexp
}

RegexStore store compiled regex to improve performance

func NewRegexStore

func NewRegexStore() *RegexStore

NewRegexStore create new regex store

func (*RegexStore) GetPattern

func (store *RegexStore) GetPattern(pattern string) *regexp.Regexp

GetPattern returns a regexp. If pattern not found, compile and store

type Route

type Route struct {
	FileName        string `toml:"-"`
	ServerNames     []string
	Interfaces      []string
	ListenAddresses []*ListenAddress `toml:"-"`
	SSL             TLSKeyCertPair
	Locations       []RouteLocation `toml:"Location"`
	DefaultLocation *RouteLocation  `toml:"-"`
}

Route a reverseproxy route

func GetRouteForHost

func GetRouteForHost(routes []*Route, host string) *Route

GetRouteForHost returns route by host (servername or route)

func GetRoutesFromAddress

func GetRoutesFromAddress(routes []Route, address ListenAddress) []*Route

GetRoutesFromAddress gets all routes assigned to an address

func LoadRoute

func LoadRoute(file string) (*Route, error)

LoadRoute loads route

func (Route) Check

func (route Route) Check(config *Config) bool

Check checks a route for errors. Returns true on success

func (Route) HasAddress

func (route Route) HasAddress(address ListenAddress) bool

HasAddress return true if route has an address

func (*Route) LoadAddress

func (route *Route) LoadAddress(config *Config) bool

LoadAddress loads an address from config. Returns false if at least one address was not found

func (Route) NeedSSL

func (route Route) NeedSSL() bool

NeedSSL return true if route needs ssl

type RouteLocation

type RouteLocation struct {
	// Toml config attributes
	Location    string
	Destination string
	SrcIPHeader string
	Regex       bool

	// Allow/deny hosts
	Allow []string
	Deny  string

	// Non toml attrs
	DestinationURL *url.URL `toml:"-"`
	Route          *Route   `toml:"-"`
	HasDenyRoule   bool     `toml:"-"`
}

RouteLocation location for route

func FindMatchingLocation

func FindMatchingLocation(routes []*Route, r *http.Request) *RouteLocation

FindMatchingLocation finds location

func (*RouteLocation) Init

func (location *RouteLocation) Init(route *Route)

Init inits a location. Gets called on loading its assigned route

func (RouteLocation) ModifyProxyRequest

func (location RouteLocation) ModifyProxyRequest(req *http.Request)

ModifyProxyRequest modifies a request to a proxy forward request

func (*RouteLocation) Ports

func (location *RouteLocation) Ports() []string

Ports returns a list with ports used by the given RouteLocation

type ServerConfig

type ServerConfig struct {
	MaxHeaderSize units.Datasize
	ReadTimeout   ConfigDuration
	WriteTimeout  ConfigDuration
}

ServerConfig configuration for webserver

type TLSKeyCertPair

type TLSKeyCertPair struct {
	Key  string
	Cert string
}

TLSKeyCertPair pair of tls key/cert file

func GetTLSCerts

func GetTLSCerts(routes []Route, address *ListenAddress) []TLSKeyCertPair

GetTLSCerts get all required certifitates/keys from routes which are assigned to the given address

func (TLSKeyCertPair) GetCertificate

func (pair TLSKeyCertPair) GetCertificate() (tls.Certificate, error)

GetCertificate gets certificate from TLSKeyCertPair

type TaskData

type TaskData struct {
	Redirect RedirectData
}

TaskData data for interface Task

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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