Documentation ¶
Index ¶
- Constants
- Variables
- func Run(global context.Context, bind string, handler http.Handler) error
- func RunAutoTLS(global context.Context, certsDir string, allowed Domains, handler http.Handler) error
- func RunTLS(global context.Context, bind string, certsDir string, handler http.Handler) error
- type Domains
- type JWTClaims
- type RequestResolver
- type Resolver
- type Route
- type RouteHandler
- type RouteHandlerFunc
- type Router
Constants ¶
const (
HeaderUser = "X-User"
)
Variables ¶
var ErrAbort = errors.New("abort")
var ErrSigningMethodUnsupported = errors.New("signing method unsupported")
Functions ¶
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.
Types ¶
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 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 ¶
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.