embedded

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderUser = "X-User"
)

Variables

View Source
var ErrAbort = errors.New("abort")
View Source
var ErrSigningMethodUnsupported = errors.New("signing method unsupported")

Functions

func Run

func Run(global context.Context, bind string, handler http.Handler) error

Run plain HTTP server. Closed automatically in case parent context cancelled.

func RunAutoTLS

func RunAutoTLS(global context.Context, certsDir string, allowed Domains, handler http.Handler) error

RunAutoTLS starts HTTPS server on :443 address, requests automatically TLS certificates from Let's encrypt on-demand, and stores obtained files in certsDir. Only domains from allowed will be requested. Closed automatically in case parent context cancelled.

func RunTLS

func RunTLS(global context.Context, bind string, certsDir string, handler http.Handler) error

RunTLS starts HTTPS server. Closed automatically in case parent context cancelled. In certs dir must be files server.crt and server.key

Types

type Domains

type Domains interface {
	Domains() map[string]bool
}

Domains repository.

func Static

func Static(domains ...string) Domains

Static domain set.

type JWTClaims

type JWTClaims struct {
	jwt.StandardClaims
	Methods []string `json:"methods,omitempty"`
}

JWTClaims defined extended JWT claims schema.

type RequestResolver

type RequestResolver interface {
	// FQDN version of domain name.
	FQDN(domain string) string
	// Domain name from request.
	Domain(req *http.Request) string
	// URL by short domain.
	URL(domain string) string
}

RequestResolver defines logic how to match incoming request and domain.

func ByDomain

func ByDomain(rootDomain string) RequestResolver

ByDomain resolves request domain based on requested host. Root domain (if defined) will be used as parent domain for all records.

func ByPath

func ByPath() RequestResolver

ByPath resolve request domain as a first segment in request URL path. It modifies request URL in case of successful resolution.

func ByRoot

func ByRoot() RequestResolver

ByRoot is convenient alias to ByDomain without root domain: assumes all records domains already in FQDN form.

type Resolver

type Resolver interface {
	// Resolve address or address with port to routable (from application) endpoint (with port if needed).
	Resolve(ctx context.Context, address string) (string, error)
}

type Route

type Route struct {
	Record    ingress.Record
	RequestID string
}

type RouteHandler

type RouteHandler interface {
	ServeRoute(writer http.ResponseWriter, request *http.Request, record Route) error
}

func JWT

func JWT(sharedKey string) RouteHandler

JWT based authorization and authentication per-group (repo). subject is defining restriction for allowed group, methods for allowed HTTP methods. Sets HeaderUser to the request object in case of success.

func Proxy

func Proxy(resolver Resolver) RouteHandler

Proxy request to endpoint. Nil resolver disable address resolution.

type RouteHandlerFunc

type RouteHandlerFunc func(writer http.ResponseWriter, request *http.Request, record Route) error

func (RouteHandlerFunc) ServeRoute

func (rhf RouteHandlerFunc) ServeRoute(writer http.ResponseWriter, request *http.Request, record Route) error

type Router

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

func New

func New(requestResolver RequestResolver, chain ...RouteHandler) *Router

New router which can be used independently or as backend for ingress. If rootDomain defined it will be added to all domains in records during Set operation in case path routing disabled.

func (*Router) Domains

func (rt *Router) Domains() map[string]bool

Domains for all known records.

func (*Router) Index

func (rt *Router) Index(enable bool)

Index page visibility.

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Router) Set

func (rt *Router) Set(ctx context.Context, records []ingress.Record) error

Set routing tables.

Jump to

Keyboard shortcuts

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