bobo

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

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

Go to latest
Published: Oct 12, 2016 License: MIT Imports: 18 Imported by: 0

README

Bobo

Build Status

Simple HTTP router for Go. Embraces and extends net/http. A good starting point for a HTTP JSON API service.

See example/example.go for details.

License

MIT Licensed, see LICENSE for details.

Documentation

Index

Constants

View Source
const (
	HEADER_CONTENT_TYPE   = "Content-Type"
	HEADER_CONTENT_LENGTH = "Content-Length"
	CONTENT_TYPE_JSON     = "application/json"
	CONTENT_TYPE_PROTOBUF = "application/x-protobuf"
	ERROR_NOT_FOUND       = "not found"
)

Variables

View Source
var Logger = logger.NewDefaultLogger("service")
View Source
var OK = map[string]string{"status": "ok"}

Functions

func JSON

func JSON(name string, fn func(*http.Request) (interface{}, bool, error)) http.Handler

Turns a transport-agnostic service method into an instrumented JSON endpoint.

func Logging

func Logging(handler http.Handler) http.Handler

Request logging middleware

func NotFound

func NotFound(err error) http.Handler

func Ok

func Ok() http.Handler

func Recovery

func Recovery(handler http.Handler) http.Handler

Panic recovery middleware

func RequestDebugging

func RequestDebugging(handler http.Handler) http.Handler

Request dumping middleware

func ServerError

func ServerError(err error) http.Handler

func Timeout

func Timeout(dur time.Duration, fn func() (interface{}, bool, error)) (interface{}, bool, error)

func ValidatePresence

func ValidatePresence(f string, i interface{}) error

func WriteJSON

func WriteJSON(status int, obj interface{}) http.Handler

func WritePB

func WritePB(status int, obj proto.Message) http.Handler

Types

type Error

type Error struct {
	Error string `json:"error"`
}

type ErrorHandler

type ErrorHandler func(error) http.Handler

type Errors

type Errors struct {
	Errors ValidationErrors `json:"errors"`
}

type Middleware

type Middleware func(http.Handler) http.Handler

type Params

type Params url.Values

func (Params) Bool

func (p Params) Bool(key string) bool

func (Params) Get

func (p Params) Get(key string) string

func (Params) Int

func (p Params) Int(key string) int

func (Params) Int32

func (p Params) Int32(key string) int32

func (Params) Int64

func (p Params) Int64(key string) int64

func (Params) Int64s

func (p Params) Int64s(key string) []int64

func (Params) Map

func (p Params) Map() (result map[string]string)

type Response

type Response interface {
	http.ResponseWriter
	Status() int
	Written() bool
}

func NewResponse

func NewResponse(rw http.ResponseWriter) Response

type Router

type Router struct {
	NotFound    ErrorHandler
	ServerError ErrorHandler
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) AddMiddleware

func (r *Router) AddMiddleware(h Middleware)

func (*Router) AddRoute

func (r *Router) AddRoute(method string, pattern string, handler http.Handler)

func (*Router) ListenAndServe

func (r *Router) ListenAndServe(addr string) (err error)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type ServiceUnavailableError

type ServiceUnavailableError struct {
	Err error
}

func (ServiceUnavailableError) Error

func (e ServiceUnavailableError) Error() string

type TimeoutError

type TimeoutError struct {
	Duration time.Duration
}

func (TimeoutError) Error

func (e TimeoutError) Error() string

type ValidationError

type ValidationError struct {
	Code  string `json:"code"`
	Field string `json:"field"`
	Title string `json:"title"`
}

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

func (ValidationErrors) Error

func (es ValidationErrors) Error() string

type Validator

type Validator map[string]func(string, interface{}) error

func (Validator) Validate

func (v Validator) Validate(s interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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