httplib

package module
v0.0.0-...-dbc1e03 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: MIT Imports: 12 Imported by: 0

README

httplib

Go library functions for HTTP services

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogRequest

func LogRequest(handler http.Handler) http.Handler

LogRequest is a middleware that logs a request HTTP status < 400 will be logged as Info HTTP status >= 400 && < 500 will be logged as Info with the body as message HTTP status >= 500 will be logged as Error with the body as message

func Recover

func Recover(handler http.Handler) http.Handler

Recover is a middleware that recovers a handler from an error and logs the traceback

func RunHTTP

func RunHTTP(serviceName string, mylog *log.Logger, h http.Handler)

RunHTTP starts a webserver with Wrapp logging and panic recovery The port number is fetched from the environment variable SERVICE_PORT FIXME: mylog parameter kept for legacy reasons, it should be dropped

func ValidateJSONSchema

func ValidateJSONSchema(path string) func(http.Handler) http.Handler

ValidateJSONSchema returns a http middleware that validates the supplied JSON schema. Will panic if the schema file can't be found and/or is invalid The validator supports streaming JSON, and will buffer all data to check its validity. If any of the streamed objects is invalid, subsequent handlers will not be called.

Types

type InvalidJSONError

type InvalidJSONError struct {
	gojsonschema.ResultErrorFields
}

type ValidationResult

type ValidationResult struct {
	Valid       bool        `json:"valid"`
	Errors      interface{} `json:"errors"`
	ObjectIndex *int        `json:"item,omitempty"`
}

func ErrorValidationResult

func ErrorValidationResult(vr *gojsonschema.Result) ValidationResult

Jump to

Keyboard shortcuts

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