http

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package http contains utilities to support traditional http server output and middleware. In particular, the Muxer object here helps you point to files that you generate, but that are not handled by the goradd web server. Examples would be a REST api, and generated CSV, PDF and image files.

Index

Constants

This section is empty.

Variables

View Source
var AppMuxer = http.NewServeMux()

AppMuxer is the application muxer that lets you do traditional http handling from behind the application facilities of session management, output buffering, etc.

It is called from the default MakeAppServer implementation.

Functions

func DisableOutputBuffering

func DisableOutputBuffering(ctx context.Context)

func ErrorHandler

func ErrorHandler(h http.Handler) http.Handler

ErrorHandler wraps the given handler in a default HTTP error handler that will respond appropriately to any panics that happen within the given handler.

Panic with an http.Error value to get a specific kind of http error to be output.

func OutputBuffer

func OutputBuffer(ctx context.Context) *bytes.Buffer

func Redirect

func Redirect(location string, errCode int)

Redirect will error such that the server will attempt to access the resource at a new location.

This will set the Location header to point to the new location.

Be sure to call page.MakeLocalPath() if the resource is pointing to a location on this server

func RegisterAppMuxerHandler

func RegisterAppMuxerHandler(prefix string, handler http.Handler)

RegisterAppMuxerHandler registers a handler for the given directory prefix.

The handler will be called with the prefix stripped away. When the prefix is stripped, a rooted path will be passed along. In other words, if the path is /api/file, the called handler will receive /file.

Note that you CAN register a handler for the root directory.

func SendBadRequest

func SendBadRequest()

func SendBadRequestMessage

func SendBadRequestMessage(message string)

func SendErrorCode

func SendErrorCode(errCode int)

SendErrorCode will cause the page to error with the given http error code.

func SendErrorMessage

func SendErrorMessage(message string, errCode int)

func SendForbidden

func SendForbidden()

SendForbidden will tell the user that he/she does not have credentials for the given resource.

func SendMethodNotAllowed

func SendMethodNotAllowed(allowedMethods ...string)

SendMethodNotAllowed will tell the user that the server is not able to perform the http method being asked. allowedMethods is a list of the allowed methods.

func SendNotFound

func SendNotFound()

func SendNotFoundMessage added in v0.17.2

func SendNotFoundMessage(message string)

func SendUnauthorized

func SendUnauthorized()

func SetBufferedOutputManager

func SetBufferedOutputManager(u User)

SetBufferedOutputManager injects the given manager as the global buffered output manager

func UseAppMuxer

func UseAppMuxer(next http.Handler) http.Handler

UseAppMuxer is called by the framework at application startup to place the application muxer in the handler stack.

Types

type BufferedResponseWriterI

type BufferedResponseWriterI interface {
	http.ResponseWriter
	Disable()
	OutputBuffer() *bytes.Buffer
}

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents an error response to an http request.

See http.Status* codes for status code constants

func (*Error) SetResponseHeader

func (e *Error) SetResponseHeader(key, value string)

SetResponseHeader sets a key-value in the header response.

type Muxer

type Muxer interface {
	// Handle associates a handler with the given pattern in the url path
	Handle(pattern string, handler http.Handler)
	// ServeHTTP sends a request to the MUX, to be forwarded on to the registered handler,
	// or responded with an unknown resource error.
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Muxer represents the typical functions available in a mux and allows you to replace the default Golang muxer here with a 3rd party mux, like the Gorilla mux.

type User

type User interface {
	// Use wraps the given handler.
	Use(http.Handler) http.Handler
}

User is the interface for http managers that can be injected into the handler stack.

func BufferedOutputManager

func BufferedOutputManager() User

Jump to

Keyboard shortcuts

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