servicehttp

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyFromHeader

func KeyFromHeader(header string, parser service.KeyParser) gokithttp.DecodeRequestFunc

KeyFromHeader produces a go-kit decoder which expects an HTTP header to contain the service key.

func KeyFromPath

func KeyFromPath(variable string, parser service.KeyParser) gokithttp.DecodeRequestFunc

KeyFromPath uses a gorilla/mux path variable as the source for the service Key.

func NewHashFilter

func NewHashFilter(a service.Accessor, reject error, self func(string) bool) xfilter.Interface

NewHashFilter constructs an xfilter that enforces device hashing to an instance that represents this server process. Any request that does not pass the self predicate will be rejected with the reject error.

The returned filter will check the request's context for a device id, using that to hash with if one is found. Otherwise, the device key is parsed from the request via device.IDHashParser.

func Redirect

func Redirect(redirectCode int) gokithttp.EncodeResponseFunc

Redirect returns a go-kit EncodeResponseFunc that redirects to the instance hashed by the accessor. If the original requestURI is populated under the go-kit key ContextKeyRequestURI, it is appended to the hashed instance.

Types

type KeyFunc

type KeyFunc func(*http.Request) ([]byte, error)

KeyFunc examines an HTTP request and produces the service key to use when finding an instance to use.

The device.IDHashParser function is a valid KeyFunc, and is the typical one used by WebPA.

type RedirectHandler

type RedirectHandler struct {
	// KeyFunc is the function used to extract a hash key from a request
	KeyFunc KeyFunc

	// Accessor produces instances given hash keys.  Note that a Subscription implements the Accessor interface.
	Accessor service.Accessor

	// RedirectCode is the HTTP status code sent as part of the redirect.  If not set, http.StatusTemporaryRedirect is used.
	RedirectCode int
}

RedirectHandler is an http.Handler that redirects all incoming requests using a key obtained from a request. The Accessor is passed the key to return the appropriate instance to redirect to.

func (*RedirectHandler) ServeHTTP

func (rh *RedirectHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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