util

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

View Source
 ___ ___ ___ _ _ ___
|   | -_|  _| | | .'|
|_|_|___|_|  \_/|__,|
`

Logo is the nerva ASCII logo. Generated via http://patorjk.com/software/taag/#p=display&f=Rectangles&t=nerva

Variables

This section is empty.

Functions

func ErrHandler

func ErrHandler(handler ErrHandle) httprouter.Handle

ErrHandler allows custom handlers to return internal server errors.

func IsValid

func IsValid(name string) bool

IsValid checks if the given name is valid according to the CommonJS spec. Besides the addition of fields to the Package Version Object, this addition to the Packages spec imposes the following restrictions on the “name” and “version” fields: 1. MUST NOT start with “-“ 2. MUST NOT contain any “/” characters 3. MUST NOT be “.” or “..” 4. SHOULD contain only URL-safe characters See http://wiki.commonjs.org/wiki/Packages/Registry#Changes_to_Packages_Spec

func LogErr

func LogErr(ctx *log.Entry, err error, reason string)

logErr logs the passed in error.

func LogFatal

func LogFatal(ctx *log.Entry, err error, reason string)

logFatal logs the passed in error and exits.

func LogRequest

func LogRequest(handle httprouter.Handle) httprouter.Handle

func LogWarn

func LogWarn(ctx *log.Entry, err error, reason string)

logWarn logs the passed in error.

func RequestContext

func RequestContext(req *http.Request) *log.Entry

func RespondJSON

func RespondJSON(w http.ResponseWriter, code int, data interface{}) error

RespondJSON encodes the passed in data as JSON-compatible string and returns it to the client.

Types

type ErrHandle

type ErrHandle func(w http.ResponseWriter, r *http.Request,
	ps httprouter.Params) error

ErrHandle is a custom HTTP handle that can optionally return an error.

func ValidatePropHandler

func ValidatePropHandler(name string, handle ErrHandle) ErrHandle

ValidatePropHandler validates the passed in property names.

type ErrorResponse

type ErrorResponse struct {
	Error  string `json:"error"`
	Reason string `json:"reason"`
}

ErrorResponse is a HTTP response.

Jump to

Keyboard shortcuts

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