errorhandler

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

README

ErrorHandler

GoDoc

Purpose

The out-of-the-box Go web-server send plain text error messages whenever an HTTP errror occurs. This package provides a simple facility to send whatever HTML page you like for error-pages.

Installation

You can use Go to install this package for you:

go get -u github.com/mwat56/go-errorhandler

Usage

This package defines the TErrorPager interface which requires just one method:

TErrorPager interface {
    // GetErrorPage returns an error page for `aStatus`.
    //
    // `aData` is the orignal error text.
    //
    // `aStatus` is the error number of the actual HTTP error.
    GetErrorPage(aData []byte, aStatus int) []byte
}

If the method's return value is empty then aData is sent as is to the remote user, otherwise the method's result is sent thus delighting your users with your customised page.

Once you've implemented such a method you call the package's Wrap() function:

Wrap(aHandler http.Handler, aPager TErrorPager) http.Handler

The arguments are:

  • aHandler is your original HTTP handler which will be wrapped by this package (and used internally).

  • aPager is the provider of error message pages as discussed above.

Additionally to the functionality discussed above the http.Handler returned by Wrap() catches (and logs to StdOut) any panics that may have occured while serving the respective current request.

In the directory _demo there is the file demo.go which shows the bare minimum of how to integrate this package with your web-server.

Licence

Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                All rights reserved
            EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the GNU General Public License for details.

Documentation

Overview

Package errorhandler implements a simple handler for HTTP error messages.

Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                All rights reserved
            EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(aHandler http.Handler, aPager TErrorPager) http.Handler

Wrap returns a handler function that includes error page handling, wrapping the given `aHandler` and calling it internally.

`aHandler` responds to the actual HTTP request.

`aPager` is the provider of error message pages.

Types

type TErrorPager

type TErrorPager interface {
	// GetErrorPage returns a HTML page for `aStatus`.
	// The return value is expected to be a valid HTML page.
	//
	// `aData` is the orignal error text.
	//
	// `aStatus` is the number of the actual HTTP error status.
	GetErrorPage(aData []byte, aStatus int) []byte
}

TErrorPager is an interface requiring a function to return the error text of an HTTP error message page.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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