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 ¶
- Variables
- func DisableOutputBuffering(ctx context.Context)
- func ErrorHandler(h http.Handler) http.Handler
- func OutputBuffer(ctx context.Context) *bytes.Buffer
- func Redirect(location string, errCode int)
- func RegisterAppMuxerHandler(prefix string, handler http.Handler)
- func SendBadRequest()
- func SendBadRequestMessage(message string)
- func SendErrorCode(errCode int)
- func SendErrorMessage(message string, errCode int)
- func SendForbidden()
- func SendMethodNotAllowed(allowedMethods ...string)
- func SendNotFound()
- func SendNotFoundMessage(message string)
- func SendUnauthorized()
- func SetBufferedOutputManager(u User)
- func UseAppMuxer(next http.Handler) http.Handler
- type BufferedResponseWriterI
- type Error
- type Muxer
- type User
Constants ¶
This section is empty.
Variables ¶
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 ErrorHandler ¶
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 Redirect ¶
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 ¶
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 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
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 ¶
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.