dynamux

package
v0.0.0-...-891d2fd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package dynamux defines a multiplexing helper for url generated at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	UID string

	Path        string
	Destination *url.URL
	Proxy       *httputil.ReverseProxy `json:"-"`
	Client      *http.Client           `json:"-"`
	Active      bool
	// Owner string // whom the link was created on behalf of
	// RessourceID string
	// Referer string
	//ClickerSessionID string
	//ClickCount       int64
	CreatedAt time.Time
	MaxAge    time.Duration

	Handler xhttp.Handler
	// contains filtered or unexported fields
}

Link defines the structure of a url generated at runtime which can collect application stats. This is an indirection url which enables processing to be done before the static resource is fetched or redirected to. Typical use would be url creation for uploaded resources. Persisting(storage, update, deletion) Links and retrieving them from the udatabase are tasks left to the user of this library.

func NewLink(id string, path string, dest *url.URL, maxage time.Duration, proxy bool) Link

NewLink returns an indirection link pointing to a resource (destination URL). It is used by a Multiplexer which can then insert custom request handling for such dynamically generated links. maxage <0 means the link is expired maxage = 0 means the link doesn not expire

func (Link) ServeHTTP

func (l Link) ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Request)

func (Link) WithHandler

func (l Link) WithHandler(h xhttp.Handler) Link

WithHandler provides the link with a middleware request handling function that should trigger before any redirection or requets proxying for instance. Can be used typically to record link statistics.

type Multiplexer

type Multiplexer struct {
	Links map[string]Link
	// contains filtered or unexported fields
}

Multiplexer is used to handle dynamically generated URLs.

func NewMultiplexer

func NewMultiplexer() *Multiplexer

NewMultiplexer creates a new dynamic link handler for serving requests to these runtime generated links.

func (m *Multiplexer) AddLink(links ...Link)

AddLink inserts a new Link into the Multiplexer.

func (*Multiplexer) ServeHTTP

func (m *Multiplexer) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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