upstream

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUpstreams

func AddUpstreams(allToAdd []Upstream)

AddUpstreams add an array of upstreams to the available upstreams

func FromMapOfArrayOfStrings

func FromMapOfArrayOfStrings(original map[string]arrayOrString) map[string][]string

FromMapOfArrayOfStrings converts a map of arrayOrString to a map of array of strings

func Initialize

func Initialize(baseDir string)

Initialize loads all upstreams and initalize a routine to refresh the read files

func Upstreams

func Upstreams() map[string]Upstream

Upstreams return a map containing all upstreams loaded

func UpstreamsPerFile

func UpstreamsPerFile() map[string][]Upstream

UpstreamsPerFile returns a map with all upstreams grouped by file where they were loaded from

Types

type BaseEndpoint

type BaseEndpoint struct {
	From         string `json:"from"`
	Regexp       string `json:"regexp"`
	UpstreamName string `json:"upstreamName"`
	// contains filtered or unexported fields
}

BaseEndpoint represents a base endpoint route

func (*BaseEndpoint) Matches

func (m *BaseEndpoint) Matches(req *http.Request) bool

Matches check if the request matches the request

func (*BaseEndpoint) Path

func (m *BaseEndpoint) Path() string

Path returns the matching path for an endpoint

type Endpoint

type Endpoint interface {
	Handle(*http.Request) (int, string, map[string][]string, io.ReadCloser)
	Matches(*http.Request) bool
	Path() string
}

Endpoint represents one route inside an Upstream

type Endpoints

type Endpoints []Endpoint

Endpoints represents a sortable array of endpoints

func (Endpoints) Len

func (a Endpoints) Len() int

func (Endpoints) Less

func (a Endpoints) Less(i, j int) bool

func (Endpoints) Swap

func (a Endpoints) Swap(i, j int)

type Origin

type Origin struct {
	File     string `json:"file"`
	LoadedAt int64  `json:"loadedAt"`
}

Origin is where the upstream was loaded from

type ProxyEndpoint

type ProxyEndpoint struct {
	BaseEndpoint
	Headers map[string][]string `json:"headers"`
	To      string              `json:"to"`
}

ProxyEndpoint proxy requests to another HTTP/S server

func (*ProxyEndpoint) Handle

func (p *ProxyEndpoint) Handle(req *http.Request) (int, string, map[string][]string, io.ReadCloser)

Handle handles requests proxying the content to another HTTP server

type StaticEndpoint

type StaticEndpoint struct {
	BaseEndpoint
	To string `json:"to"`
}

StaticEndpoint is an endpoint that responds with file from disk

func (*StaticEndpoint) Handle

func (s *StaticEndpoint) Handle(req *http.Request) (int, string, map[string][]string, io.ReadCloser)

Handle handles incoming request matching to files in disk

type Upstream

type Upstream struct {
	Name            string            `json:"name"`
	Origin          Origin            `json:"origin"`
	ProxyEndpoints  []*ProxyEndpoint  `json:"proxyEndpoints"`
	StaticEndpoints []*StaticEndpoint `json:"staticEndpoints"`
}

Upstream represents a place where requests can be directed to

func (Upstream) Endpoints

func (u Upstream) Endpoints() []Endpoint

Endpoints returns all the endpoints available for the upstream

Jump to

Keyboard shortcuts

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