httpendpoint

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Overview

Package httpendpoint provides types that allow web-service handlers to be registered with an HTTP server.

Types in this package represent the interface between the HttpServer facility (which is a thin layer over Go's http.Server) and the Granitic ws and handler packages that define web-services.

In most cases, user applications will not need to interact with the types in this package. Instead they will define components of type handler.WsHandler (which already implements the key HttpEndpointProvider interface below) and the framework will automatically register them with the HttpServer facility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpEndPoint

type HttpEndPoint struct {
	// A map of HTTP method names to a regular expression pattern (eg GET=^/health-check$)
	MethodPatterns map[string]string

	// A handler implementing Go's built-in http.Handler interface
	Handler http.Handler
}

HttpEndPoint associates HTTP methods (GET, POST etc) and path-matching regular expressions with a handler.

type HttpEndpointProvider

type HttpEndpointProvider interface {
	//SupportedHttpMethods returns the HTTP methods (GET, POST, PUT etc) that the endpoint supports.
	SupportedHttpMethods() []string

	// RegexPattern returns an un-compiled regular expression that will be applied to the path element (e.g excluding scheme, domain and query parameters)
	// to potentially match the request to this endpoint.
	RegexPattern() string

	// ServeHttp handles an HTTP request, including writing normal and abnormal responses. Returns a context that may have
	// been modified.
	ServeHttp(ctx context.Context, w *HttpResponseWriter, req *http.Request) context.Context

	// VersionAware returns true if this endpoint supports request version matching.
	VersionAware() bool

	// SupportsVersion returns true if this endpoint supports the version of functionality required by the requester. Behaviour is undefined if
	// VersionAware is false. Version matching is application-specific and not defined by Granitic.
	SupportsVersion(version RequiredVersion) bool

	// AutoWireable returns false if this endpoint should not automatically be registered with HTTP servers.
	AutoWireable() bool
}

Implemented by a component that is able to support a web-service request with a particular path.

type HttpResponseWriter added in v1.1.0

type HttpResponseWriter struct {

	// Whether or not any data has already been sent to the underlying http.ResponseWriter.
	DataSent bool

	// The HTTP status code sent to the response or zero if no code yet sent.
	Status int

	// How many bytes have been sent to the response so far (excluding headers).
	BytesServed int
	// contains filtered or unexported fields
}

A wrapper over http.ResponseWriter that provides Granitic with better visibility on the state of response writing.

func NewHttpResponseWriter added in v1.1.0

func NewHttpResponseWriter(rw http.ResponseWriter) *HttpResponseWriter

Create a new WsHTTPResponseWriter wrapping the supplied http.ResponseWriter

func (*HttpResponseWriter) Header added in v1.1.0

func (w *HttpResponseWriter) Header() http.Header

Header calls through to http.ResponseWriter.Header()

func (*HttpResponseWriter) Write added in v1.1.0

func (w *HttpResponseWriter) Write(b []byte) (int, error)

Write calls through to http.ResponseWriter.Write while keeping track of the number of bytes sent.

func (*HttpResponseWriter) WriteHeader added in v1.1.0

func (w *HttpResponseWriter) WriteHeader(i int)

WriteHeader sets the HTTP status code of the HTTP response. If this method is called more than once, only the first value is sent to the underlying HTTP response.

type RequestedVersionExtractor

type RequestedVersionExtractor interface {
	// Extract examines an HTTP request to determine what version of functionality is required.
	Extract(*http.Request) RequiredVersion
}

RequestedVersionExtractor is implemented by applications to create a component that can determine what version of functionality is required by an incoming HTTP request

type RequiredVersion

type RequiredVersion map[string]interface{}

A semi-structured type to allow applications flexibility in defining what a 'version' is.

Jump to

Keyboard shortcuts

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