http

package
v0.0.0-...-48af17f Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2017 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextKeys = Keys{
		TID:      "tid",
		CID:      "cid",
		LOG:      "requestLog",
		TOKEN:    "requestToken",
		IDENTITY: "requestIdentity",
		AUDITOR:  "requestAuditor",
	}
)

Functions

func Bytes

func Bytes(w http.ResponseWriter, status int, result []byte) error

func Err

func Err(w http.ResponseWriter, err error) error

func Get

func Get(r *http.Request, key interface{}) interface{}

func GetLog

func GetLog(r *http.Request) l.Logger

func GetTID

func GetTID(r *http.Request) string

func GetToken

func GetToken(r *http.Request) string

func Handler

func Handler(handler HTTPHandlerFunc) http.HandlerFunc

Handler wraps a library handler func nto a http handler func

func JSON

func JSON(w http.ResponseWriter, status int, result interface{}) error

func ReadByContentType

func ReadByContentType(r *http.Request, data interface{}) error

ReadByContentType reads data from context using the Content-Type header to define the media type

func ReadJSON

func ReadJSON(r *http.Request, data interface{}) error

ReadJSON unmarshals from provided context a json media into data

func Status

func Status(w http.ResponseWriter, status int) error

func Wrap

func WriteByAccept

func WriteByAccept(w http.ResponseWriter, r *http.Request, status int, result interface{}) error

WriteByAccept writes data to context using the Accept header to define the media type

Types

type AuditHandler

type AuditHandler func(http.ResponseWriter, *http.Request) error

func (AuditHandler) ServeHTTP

func (h AuditHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Auditor

type Auditor struct {
	l.Logger
	TID      string
	CID      string
	Identity *Identity
}

func GetAuditor

func GetAuditor(r *http.Request) *Auditor

type BaseHandler

type BaseHandler struct {
}

func (BaseHandler) Err

func (h BaseHandler) Err(w http.ResponseWriter, err error) error

func (BaseHandler) JSON

func (h BaseHandler) JSON(w http.ResponseWriter, status int, result interface{}) error

func (BaseHandler) Status

func (h BaseHandler) Status(w http.ResponseWriter, status int) error

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request) error

func (ErrorHandler) ServeHTTP

func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPHandler

type HTTPHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) error
}

HTTPHandler is a contract for fast http handlers

type HTTPHandlerFunc

type HTTPHandlerFunc func(http.ResponseWriter, *http.Request) error

HTTPHandlerFunc is a function to handle fasthttp requrests

func Audit

func Audit(handler HTTPHandlerFunc) HTTPHandlerFunc

Audit wraps the provided HTTPHandlerFunc with access logging, error and audit control

func Error

func Error(handler HTTPHandlerFunc) HTTPHandlerFunc

Error wraps the provided HTTPHandlerFunc with exception control

func Log

func Log(handler HTTPHandlerFunc) HTTPHandlerFunc

Log wraps the provided HTTPHandlerFunc with access logging control

func (HTTPHandlerFunc) ServeHTTP

func (h HTTPHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error

HandleRequest is the contract with HTTPHandler interface

type HTTPHandlerWrapper

type HTTPHandlerWrapper func(HTTPHandlerFunc) HTTPHandlerFunc

HTTPHandlerWrapper is a function to create handler wraps to execute like a chain mechanism between the handlers

type Identity

type Identity struct {
	Token string      `json:"token"`
	Value interface{} `jsno:"value"`
}

func GetIdentity

func GetIdentity(r *http.Request) *Identity

type Keys

type Keys struct {
	TID      string
	CID      string
	LOG      string
	TOKEN    string
	IDENTITY string
	AUDITOR  string
}

type LogHandler

type LogHandler func(http.ResponseWriter, *http.Request) error

func (LogHandler) ServeHTTP

func (h LogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	// Status returns the status code of the response or 200 if the response has
	// not been written (as this is the default response code in net/http)
	Status() int
	// Written returns whether or not the ResponseWriter has been written.
	Written() bool
	// Size returns the size of the response body.
	Size() int
}

ResponseWriter is a wrapper function to store status and body length of the request

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) ResponseWriter

NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter

type SimpleHTTPHandler

type SimpleHTTPHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
}

SimpleHTTPHandler is a contract for fast http handlers

Jump to

Keyboard shortcuts

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