webutils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2016 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package webutils contains commonly used web utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLogHandler

func AccessLogHandler(h http.Handler, logger *logging.Logger) http.Handler

AccessLogHandler logs HTTP requests that HTTP sever handles. It logs information about remote address, X-Forwarded-For or X-Real-Ip, HTTP method, request URI, HTTP protocol, HTTP response status, total bytes written to http.ResponseWriter, response duration, HTTP referrer and HTTP client user agent.

func DumpDBHandler

func DumpDBHandler(w http.ResponseWriter, r *http.Request, db *bolt.DB)

DumpDBHandler writes all data from BoltDB database to a http.ResponseWriter.

func GetHost

func GetHost(r *http.Request) string

GetHost returns request's host perpended with protocol: protocol://host.

func GetIPs

func GetIPs(r *http.Request) string

GetIPs returns all possible IPs found in HTTP request.

func IPFromRemoteAddr

func IPFromRemoteAddr(s string) string

IPFromRemoteAddr returns an IP without port from request's remote address.

func ReadRequestBody

func ReadRequestBody(w http.ResponseWriter, r *http.Request, v interface{}) error

ReadRequestBody unmarshals JSON encoded HTTP request body into an arbitrary interface. In case of error, it writes appropriate JSON-encoded response to http.ResponseWriter, so the calling handler should not write new data if this function returns error.

Types

type FormErrors

type FormErrors struct {
	Errors      []string            `json:"errors"`
	FieldErrors map[string][]string `json:"field-errors"`
}

FormErrors represent structure errors returned by API server to request based on HTML form data.

func NewError

func NewError(e string) FormErrors

NewError initializes FormErrors with one general error.

func NewFieldError

func NewFieldError(field, e string) FormErrors

NewFieldError initializes FormErrors with one field error.

func (*FormErrors) AddError

func (f *FormErrors) AddError(e string)

AddError appends an error to a list of general errors.

func (*FormErrors) AddFieldError

func (f *FormErrors) AddFieldError(field, e string)

AddFieldError appends an error to a list of field specific errors.

func (FormErrors) HasErrors

func (f FormErrors) HasErrors() bool

HasErrors returns weather FormErrors instance contains at leas one error.

Jump to

Keyboard shortcuts

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