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 Provider 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 HTTPResponseWriter ¶
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 }
HTTPResponseWriter is a wrapper over http.ResponseWriter that provides Granitic with better visibility on the state of response writing.
func NewHTTPResponseWriter ¶
func NewHTTPResponseWriter(rw http.ResponseWriter) *HTTPResponseWriter
NewHTTPResponseWriter creates a new HTTPResponseWriter wrapping the supplied http.ResponseWriter
func (*HTTPResponseWriter) Header ¶
func (w *HTTPResponseWriter) Header() http.Header
Header calls through to http.ResponseWriter.Header()
func (*HTTPResponseWriter) Write ¶
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 ¶
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 HandlerMethods ¶
type HandlerMethods 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 }
HandlerMethods associates HTTP methods (GET, POST etc) and path-matching regular expressions with a handler.
type Provider ¶
type Provider 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 }
Provider is implemented by a component that is able to support a web-service request with a particular path.
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{}
RequiredVersion is a semi-structured type to allow applications flexibility in defining what a 'version' is.