Documentation ¶
Index ¶
- Constants
- Variables
- func CreateHTTP(addr string, handle http.Handler) (*http.Server, net.Listener, error)
- func CreateTLS(addr string, conf *tls.Config, handle http.Handler) (*http.Server, net.Listener, error)
- func GetMethods(m string) []string
- func HasMethod(mo []string, m string) bool
- func IdentityCall(c *Context, nx NextHandler)
- func IsWebSocketRequest(r *http.Request) bool
- func LoadTLS(cert, key string) (*tls.Config, error)
- func LunchHTTP(addr string, handle http.Handler) error
- func LunchTLS(addr string, conf *tls.Config, handle http.Handler) error
- func MakeBaseListener(addr string, conf *tls.Config) (net.Listener, error)
- func MakeBaseServer(l net.Listener, handle http.Handler, c *tls.Config) (*http.Server, net.Listener, error)
- func MakeListener(addr, ts string, conf *tls.Config) (net.Listener, error)
- func MatchesMethod(mo []string, w http.ResponseWriter, r *http.Request, c Collector, fx RHandler)
- func ServeFile(indexFile, dir, file string, res http.ResponseWriter, req *http.Request) error
- func WriteHead(c *Context, h *Head)
- func WriteRawHead(c http.ResponseWriter, h *Head)
- type BufferPool
- type ChainRouta
- type ChainRouter
- type Collector
- func (c Collector) Clear()
- func (c Collector) Clone() Collector
- func (c Collector) Copy(m map[string]interface{})
- func (c Collector) Each(fx StringEachfunc)
- func (c Collector) Get(k string) interface{}
- func (c Collector) Has(k string) bool
- func (c Collector) HasMatch(k string, v interface{}) bool
- func (c Collector) Keys() []string
- func (c Collector) Remove(k string)
- func (c Collector) Set(k string, v interface{})
- func (c Collector) ToMap() map[string]interface{}
- type Context
- type CustomError
- type EncodeHandler
- type Encoder
- type FS
- type FlatChain
- func (r *FlatChain) Chain(rx FlatChains) FlatChains
- func (r *FlatChain) ChainFlat(h FlatHandler) FlatChains
- func (r *FlatChain) ChainHandleFunc(h http.HandlerFunc) FlatChains
- func (r *FlatChain) ChainHandler(h http.Handler) FlatChains
- func (r *FlatChain) Handle(res http.ResponseWriter, req *http.Request, co Collector)
- func (r *FlatChain) HandleContext(c *Context)
- func (r *FlatChain) Link(rx FlatChains) FlatChains
- func (r *FlatChain) LinkFlat(h FlatHandler) FlatChains
- func (r *FlatChain) LinkHandleFunc(h http.HandlerFunc) FlatChains
- func (r *FlatChain) NChain(rx FlatChains) FlatChains
- func (r *FlatChain) ServeHTTP(res http.ResponseWriter, req *http.Request)
- type FlatChains
- func ChainFlats(mo FlatChains, so ...FlatChains) FlatChains
- func ChooseFlat(methods, pattern string, pass, fail FlatChains, lg *log.Logger) FlatChains
- func FlatChainHandlerWrap(h http.Handler, lg *log.Logger) FlatChains
- func FlatChainIdentity(lg *log.Logger) FlatChains
- func FlatChainWrap(h http.HandlerFunc, lg *log.Logger) FlatChains
- func FlatHandleFunc(methods, pattern string, r http.HandlerFunc, lg *log.Logger) FlatChains
- func FlatHandleHandler(methods, pattern string, r http.Handler, lg *log.Logger) FlatChains
- func FlatPass(methods, pattern string, lg *log.Logger) FlatChains
- func FlatRoute(methods, pattern string, fx FlatHandler, lg *log.Logger) FlatChains
- func FlatRouteBuild(methods []string, pattern *reggy.ClassicMatchMux, fx FlatHandler, ...) FlatChains
- func FlatSocket(header http.Header, hs SocketHandler, logg *log.Logger) FlatChains
- func Logger(log *log.Logger) FlatChains
- func NewSockets(upgrader *websocket.Upgrader, headers http.Header, hs SocketHandler, ...) FlatChains
- func Redirect(path string) FlatChains
- func ThenFlat(methods, pattern string, pass FlatChains, log *log.Logger) FlatChains
- type FlatHandler
- func FSContextHandler(fs *FS, fail http.HandlerFunc) FlatHandler
- func FSCtxHandler(fs *FS) FlatHandler
- func FlatHandlerFuncWrap(h http.HandlerFunc) FlatHandler
- func FlatHandlerWrap(h http.Handler) FlatHandler
- func LoggerHandler() FlatHandler
- func PanicContextHandler(fx FlatHandler, p func(*Context, interface{})) FlatHandler
- func PanicFlatHandler(fx FlatHandler, p PanicHandler) FlatHandler
- type HTML
- type HTTPCodec
- type HTTPDecodeHandler
- type HTTPDecoder
- type Head
- type HeadEncodeHandler
- type HeadEncoder
- type JSON
- type JSONP
- type Message
- type NextHandler
- type PProf
- type PanicHandler
- type RHandler
- func BuildMatchesMethod(mo []string, fx RHandler) RHandler
- func FSHandler(fs *FS, fail http.HandlerFunc) RHandler
- func FSServe(fs http.FileSystem, stripPrefix string, fail http.HandlerFunc) RHandler
- func WrapRouteHandler(r http.Handler) RHandler
- func WrapRouteHandlerFunc(r http.HandlerFunc) RHandler
- type ResponseWriter
- type SocketCodec
- type SocketDecodeHandler
- type SocketDecoder
- type SocketHandler
- type SocketHub
- type SocketHubHandler
- type SocketStore
- type SocketWorker
- type SocketWorkerHandler
- type StringEachfunc
- type SyncCollector
- func (c *SyncCollector) Clear()
- func (c *SyncCollector) Clone() *SyncCollector
- func (c *SyncCollector) Copy(m map[string]interface{})
- func (c *SyncCollector) Each(fx StringEachfunc)
- func (c *SyncCollector) Get(k string) interface{}
- func (c *SyncCollector) Has(k string) bool
- func (c *SyncCollector) HasMatch(k string, v interface{}) bool
- func (c *SyncCollector) Keys() []string
- func (c *SyncCollector) Remove(k string)
- func (c *SyncCollector) Set(k string, v interface{})
- func (c *SyncCollector) ToMap() map[string]interface{}
- type TCPKeepAliveListener
- type Text
- type Websocket
- type WebsocketMessage
- type XML
Constants ¶
const ( // ContentBinary header value for binary data. ContentBinary = "application/octet-stream" // ContentHTML header value for HTML data. ContentHTML = "text/html" // ContentJSON header value for JSON data. ContentJSON = "application/json" // ContentJSONP header value for JSONP data. ContentJSONP = "application/javascript" // ContentLength header constant. ContentLength = "Content-Length" // ContentText header value for Text data. ContentText = "text/plain" // ContentType header constant. ContentType = "Content-Type" // ContentXHTML header value for XHTML data. ContentXHTML = "application/xhtml+xml" // ContentXML header value for XML data. ContentXML = "text/xml" )
Variables ¶
var ( // ErrTimeout provides a timeout error ErrTimeout = errors.New("Timeout on Connection") // ErrorNotFind stands for errors when value not find ErrorNotFind = errors.New("NotFound!") // ErrorBadRequestType stands for errors when the interface{} recieved can not // be type asserted as a *http.Request object ErrorBadRequestType = errors.New("type is not a *http.Request") // ErrorBadHTTPPacketType stands for errors when the interface{} received is not a //bad request type ErrorBadHTTPPacketType = errors.New("type is not a HTTPPacket") // ErrorNoConnection describe when a link connection does not exists" ErrorNoConnection = errors.New("NoConnection") // ErrBadConn represent a bad connection ErrBadConn = errors.New("Bad Connection Received") )
var BasicHTTPCodec = NewHTTPCodec(SimpleEncoder, MessageDecoder)
BasicHTTPCodec returns a new codec based on the basic deocder and encoder
var BasicHeadEncoder = NewHeadEncoder(func(c *Context, h *Head) error { WriteHead(c, h) return nil })
BasicHeadEncoder provides a basic encoder for writing the response headers and status information,it provides the flexibility to build even more reusable and useful header writing methods
var BasicSocketCodec = NewSocketCodec(ByteEncoder, ByteSocketDecoder)
BasicSocketCodec returns a codec using the socket encoder and decoder
var ByteEncoder = NewEncoder(func(w io.Writer, bu interface{}) (int, error) { bo, ok := bu.([]byte) if !ok { return 0, ErrInvalidByteType } return w.Write(bo) })
ByteEncoder provides the basic websocket message encoder for encoding json messages
var ByteSocketDecoder = NewSocketDecoder(func(t int, bu []byte) (interface{}, error) { return bu, nil })
ByteSocketDecoder provides the basic websocket decoder which justs returns a decoder
var ErrClosed = errors.New("Already Closed")
ErrClosed is returned to indicated an already closed struct
var ErrInvalidByteType = errors.New("interface not a []byte")
ErrInvalidByteType is returned when the interface is ot a []byte
var ErrInvalidType = errors.New("Unsupported Type")
ErrInvalidType is returned when the type required is not met
var ErrNoBody = errors.New("Http Request Has no body")
ErrNoBody is returned when the request has no body
var ErrNotHTTP = errors.New("interface type is not HTTPRequest")
ErrNotHTTPParameter is returned when an HTTPort receives a wrong interface type
var ErrNotHijackable = errors.New("ResponseWriter cant be Hijacked")
ErrNotHijackable is returned when a response writer can not be hijacked
var HTMLEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { hop, ok := d.(*HTML) if !ok { return 0, NewCustomError("HTML", "encoder received wrong type,expected HTML struct type") } bou := bufPool.Get() if err := hop.Template.ExecuteTemplate(bou, hop.Layout, hop.Binding); err != nil { return 0, err } nd, err := bou.WriteTo(w) bufPool.Put(bou) return int(nd), err })
HTMLEncoder provides the jsonp encoder for encoding json messages
var JSONEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { jso, ok := d.(*JSON) if !ok { return 0, NewCustomError("JSON", "Wrong type,expected JSON type") } if jso.Stream { return 1, json.NewEncoder(w).Encode(jso.Data) } var res []byte var err error if jso.Indent { res, err = json.MarshalIndent(jso.Data, "", " ") res = append(res, '\n') } else { res, err = json.Marshal(jso.Data) } if err != nil { return 0, err } if jso.UnEscapeHTML { res = bytes.Replace(res, []byte("\\u003c"), []byte("<"), -1) res = bytes.Replace(res, []byte("\\u003e"), []byte(">"), -1) res = bytes.Replace(res, []byte("\\u0026"), []byte("&"), -1) } w.Write(res) return 0, nil })
JSONEncoder provides the jsonp encoder for encoding json messages
var JSONPEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { var res []byte var err error jop, ok := d.(*JSONP) if !ok { return 0, NewCustomError("JSONP", "encoder expected JSONP type") } if jop.Indent { res, err = json.MarshalIndent(jop.Data, "", " ") res = append(res, '\n') } else { res, err = json.Marshal(jop.Data) } if err != nil { return 0, err } var fos []byte fos = append(fos, []byte(jop.Callback+"(")...) fos = append(fos, res...) fos = append(fos, []byte(");")...) return w.Write(fos) })
JSONPEncoder provides the jsonp encoder for encoding json messages
var MessageDecoder = NewHTTPDecoder(func(req *Context) (*Message, error) {
return loadData(req)
})
MessageDecoder provides the message decoding decoder for *Context objects
var SimpleEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { switch d.(type) { case string: so, _ := d.(string) return w.Write([]byte(so)) case []byte: bo, _ := d.([]byte) return w.Write(bo) } return 0, NewCustomError("SimpleEncoder", "data is neither a 'string' or '[]byte' type ") })
SimpleEncoder provides simple encoding that checks if the value given is a string or []byte else returns an error
var TextEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { tx, ok := d.(*Text) if !ok { return 0, NewCustomError("TextEncoder", "received type is not a Text{}") } return w.Write([]byte(tx.Data)) })
TextEncoder provides the jsonp encoder for encoding json messages
var XMLEncoder = NewEncoder(func(w io.Writer, d interface{}) (int, error) { jso, ok := d.(*XML) if !ok { return 0, NewCustomError("XML", "Wrong type,expected XML type") } var res []byte var err error if jso.Indent { res, err = xml.MarshalIndent(jso.Data, "", " ") res = append(res, '\n') } else { res, err = xml.Marshal(jso.Data) } if err != nil { return 0, err } return w.Write(res) })
XMLEncoder provides the jsonp encoder for encoding json messages
Functions ¶
func CreateHTTP ¶
CreateHTTP returns a http server using the giving address
func CreateTLS ¶
func CreateTLS(addr string, conf *tls.Config, handle http.Handler) (*http.Server, net.Listener, error)
CreateTLS returns a http server using the giving address
func GetMethods ¶
GetMethods turns a string of space separated methods into a list
func IdentityCall ¶
func IdentityCall(c *Context, nx NextHandler)
IdentityCall provides a Identity caller for FlatHandler
func IsWebSocketRequest ¶
IsWebSocketRequest returns true if a http.Request object is based on websocket standards
func MakeBaseListener ¶
MakeBaseListener returns a new net.Listener(*TCPKeepAliveListener) for http.Request
func MakeBaseServer ¶
func MakeBaseServer(l net.Listener, handle http.Handler, c *tls.Config) (*http.Server, net.Listener, error)
MakeBaseServer returns a new http.Server using the provided listener
func MakeListener ¶
MakeListener returns a new net.Listener for http.Request
func MatchesMethod ¶
MatchesMethod provides a factory function for matching sets of methods against a reqests method
func ServeFile ¶
ServeFile provides a file handler for serving files, it takes an indexFile which defines a default file to look for if the file path is a directory ,then the directory to use and the file to be searched for
func WriteRawHead ¶
func WriteRawHead(c http.ResponseWriter, h *Head)
WriteRawHead writes a head struct into a ResponseWriter
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Pulled from the github.com/oxtoacart/bpool package (Apache licensed).
func NewBufferPool ¶
func NewBufferPool(size int, mem int) (bp *BufferPool)
NewBufferPool creates a new BufferPool bounded to the given size.
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() (b *bytes.Buffer)
Get gets a Buffer from the BufferPool, or creates a new one if none are available in the pool.
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(b *bytes.Buffer)
Put returns the given Buffer to the BufferPool.
type ChainRouta ¶
type ChainRouta struct { *reggy.ClassicMatchMux Handler RHandler }
ChainRouta provides a single routing rule instance for Router
type ChainRouter ¶
type ChainRouter struct { FlatChains Fail RHandler Log *log.Logger // contains filtered or unexported fields }
ChainRouter provides an alternative routing strategy of registered ChainRoutas using the FlatChains, its process is when any stack matches, its passed the requests to that handler and continues on, but if non matching is found,it executes a failure routine i.e it matches as many as possible unless non matches
func NewChainRouter ¶
func NewChainRouter(fail RHandler, lg *log.Logger) *ChainRouter
NewChainRouter returns a new ChainRouter instance
func (*ChainRouter) BareRule ¶
func (r *ChainRouter) BareRule(mo, pattern string, fx RHandler)
BareRule defines a matching rule for a specified pattern
func (*ChainRouter) Handle ¶
func (r *ChainRouter) Handle(w http.ResponseWriter, rq *http.Request, _ Collector)
Handle meets the FlatHandler interface for serving http requests
func (*ChainRouter) Rule ¶
func (r *ChainRouter) Rule(mo, pattern string, fx FlatHandler) FlatChains
Rule defines a matching rule which returns a flatchain
func (*ChainRouter) ServeHTTP ¶
func (r *ChainRouter) ServeHTTP(w http.ResponseWriter, rq *http.Request)
ServeHTTP provides the handling of http requests and meets the http.Handler interface
type Collector ¶
type Collector map[string]interface{}
Collector defines a typ of map string
func (Collector) Each ¶
func (c Collector) Each(fx StringEachfunc)
Each iterates through all items in the collector
type Context ¶
type Context struct { *SyncCollector Req *http.Request Res ResponseWriter Log *log.Logger }
Context provides a resource holder for each request and response pair with internal mappings for storing data
func NewContext ¶
func NewContext(res http.ResponseWriter, req *http.Request) *Context
NewContext returns a new http context
func NewContextWith ¶
NewContextWith returns a new http context with a custom logger
type CustomError ¶
type CustomError struct {
// contains filtered or unexported fields
}
CustomError provides a custom error message format using a message pattern 'title: message'
func NewCustomError ¶
func NewCustomError(title, mesg string) CustomError
NewCustomError provides a function instance generator
func (CustomError) String ¶
func (c CustomError) String() string
String returns the message of the CustomError struct
type EncodeHandler ¶
EncodeHandler provides a handler for http encoding function
type Encoder ¶
Encoder takes an inteface and encodes it into a []byte slice
func NewEncoder ¶
func NewEncoder(fx EncodeHandler) Encoder
NewEncoder provides a nice way of build an Encoder
type FS ¶
type FS struct { http.FileSystem Strip string Header http.Header }
FS provides a configurable struct that provides a http.FileSystem with extra customization options
type FlatChain ¶
type FlatChain struct {
// contains filtered or unexported fields
}
FlatChain provides a simple middleware like
func NewFlatChain ¶
func NewFlatChain(fx FlatHandler, loga *log.Logger) *FlatChain
NewFlatChain returns a new flatchain instance
func (*FlatChain) Chain ¶
func (r *FlatChain) Chain(rx FlatChains) FlatChains
Chain sets the next flat chains else passes it down to the last chain to set as next chain,returning itself
func (*FlatChain) ChainFlat ¶
func (r *FlatChain) ChainFlat(h FlatHandler) FlatChains
ChainFlat returns a new flatchain using a provided FlatHandler
func (*FlatChain) ChainHandleFunc ¶
func (r *FlatChain) ChainHandleFunc(h http.HandlerFunc) FlatChains
ChainHandleFunc returns a new flatchain using a http.HandlerFunc as a chain wrap
func (*FlatChain) ChainHandler ¶
func (r *FlatChain) ChainHandler(h http.Handler) FlatChains
ChainHandler returns a new flatchain using a http.Handler as a chain wrap
func (*FlatChain) HandleContext ¶
HandleContext calls the next chain if any
func (*FlatChain) Link ¶
func (r *FlatChain) Link(rx FlatChains) FlatChains
Link connects a new FlatChain but bounds it as a new unique chain and not part of the current chain of the FlatChain being connected to
func (*FlatChain) LinkFlat ¶
func (r *FlatChain) LinkFlat(h FlatHandler) FlatChains
LinkFlat returns a new flatchain using a provided FlatHandler
func (*FlatChain) LinkHandleFunc ¶
func (r *FlatChain) LinkHandleFunc(h http.HandlerFunc) FlatChains
LinkHandleFunc returns a new flatchain using a http.HandlerFunc as a chain wrap
func (*FlatChain) NChain ¶
func (r *FlatChain) NChain(rx FlatChains) FlatChains
NChain sets the next flat chains else passes it down to the last chain to set as next chain,returning the the supplied chain
type FlatChains ¶
type FlatChains interface { ChainHandleFunc(h http.HandlerFunc) FlatChains ChainHandler(h http.Handler) FlatChains ChainFlat(h FlatHandler) FlatChains ServeHTTP(http.ResponseWriter, *http.Request) Handle(http.ResponseWriter, *http.Request, Collector) HandleContext(*Context) Chain(FlatChains) FlatChains NChain(FlatChains) FlatChains }
FlatChains define a simple flat chain
func ChainFlats ¶
func ChainFlats(mo FlatChains, so ...FlatChains) FlatChains
ChainFlats chains second flats to the first flatchain and returns the first flatchain
func ChooseFlat ¶
func ChooseFlat(methods, pattern string, pass, fail FlatChains, lg *log.Logger) FlatChains
ChooseFlat provides a binary operation for handling routing using flatchains,it inspects the requests where if it matches its validation parameters, the `pass` chain is called else calls the 'fail' chain if no match but still passes down the requests through the returned chain
func FlatChainHandlerWrap ¶
func FlatChainHandlerWrap(h http.Handler, lg *log.Logger) FlatChains
FlatChainHandlerWrap provides a chain wrap for http.Handler with an optional log argument
func FlatChainIdentity ¶
func FlatChainIdentity(lg *log.Logger) FlatChains
FlatChainIdentity returns a chain that calls the next automatically
func FlatChainWrap ¶
func FlatChainWrap(h http.HandlerFunc, lg *log.Logger) FlatChains
FlatChainWrap provides a chain wrap for http.Handler with an optional log argument
func FlatHandleFunc ¶
func FlatHandleFunc(methods, pattern string, r http.HandlerFunc, lg *log.Logger) FlatChains
FlatHandleFunc returns a FlatChain that wraps a http.HandleFunc for execution
func FlatHandleHandler ¶
FlatHandleHandler returns a flatchain that wraps a http.Handler
func FlatPass ¶
func FlatPass(methods, pattern string, lg *log.Logger) FlatChains
FlatPass uses FlatRoute but passes on the next caller immediately
func FlatRoute ¶
func FlatRoute(methods, pattern string, fx FlatHandler, lg *log.Logger) FlatChains
FlatRoute provides a new routing system based on the middleware stack and if a request matches then its passed down the chain else ignored
func FlatRouteBuild ¶
func FlatRouteBuild(methods []string, pattern *reggy.ClassicMatchMux, fx FlatHandler, lg *log.Logger) FlatChains
FlatRouteBuild lets you control what methods and matcher gets used to create a flatchain
func FlatSocket ¶
func FlatSocket(header http.Header, hs SocketHandler, logg *log.Logger) FlatChains
FlatSocket returns a socket Chain using a default upgraders
func Logger ¶
func Logger(log *log.Logger) FlatChains
Logger returns a new logger chain for logger incoming requests using a custom logger
func NewSockets ¶
func NewSockets(upgrader *websocket.Upgrader, headers http.Header, hs SocketHandler, logg *log.Logger) FlatChains
NewSockets returns a new websocket port
func Redirect ¶
func Redirect(path string) FlatChains
Redirect redirects all incoming request to the path
func ThenFlat ¶
func ThenFlat(methods, pattern string, pass FlatChains, log *log.Logger) FlatChains
ThenFlat provides a binary operation for handling routing using flatchains,it inspects the requests where if it matches the given criteria passes off to the supplied Chain else passes it down its own chain scope
type FlatHandler ¶
type FlatHandler func(*Context, NextHandler)
FlatHandler provides a handler for flatchain
func FSContextHandler ¶
func FSContextHandler(fs *FS, fail http.HandlerFunc) FlatHandler
FSContextHandler returns a valid FlatHandler
func FlatHandlerFuncWrap ¶
func FlatHandlerFuncWrap(h http.HandlerFunc) FlatHandler
FlatHandlerFuncWrap provides a chain wrap for http.Handler with an optional log argument
func FlatHandlerWrap ¶
func FlatHandlerWrap(h http.Handler) FlatHandler
FlatHandlerWrap provides a chain wrap for http.Handler with an optional log argument
func LoggerHandler ¶
func LoggerHandler() FlatHandler
LoggerHandler creates a new FlatHandler using a giving log instance
func PanicContextHandler ¶
func PanicContextHandler(fx FlatHandler, p func(*Context, interface{})) FlatHandler
PanicContextHandler returns a new FlatHandler which handles panics which may occure
func PanicFlatHandler ¶
func PanicFlatHandler(fx FlatHandler, p PanicHandler) FlatHandler
PanicFlatHandler returns a new FlatHandler which handles panics which may occure
type HTTPCodec ¶
type HTTPCodec interface { Encoder HTTPDecoder }
HTTPCodec provides a interface define method for custom message formats
func NewHTTPCodec ¶
func NewHTTPCodec(e Encoder, d HTTPDecoder) HTTPCodec
NewHTTPCodec returns a new http codec
func UseHTTPEncoder ¶
UseHTTPEncoder wires up the MessageDecoder as an automatic decoder
type HTTPDecodeHandler ¶
HTTPDecodeHandler provides a base decoder function type
type HTTPDecoder ¶
HTTPDecoder provides a single member rule that takes a []byte and decodes it into its desired format
func NewHTTPDecoder ¶
func NewHTTPDecoder(fx HTTPDecodeHandler) HTTPDecoder
NewHTTPDecoder provides a nice way of build an HTTPEncoder
type HeadEncodeHandler ¶
HeadEncodeHandler provides a handler for http encoding function
type HeadEncoder ¶
HeadEncoder takes an inteface and encodes it into a []byte slice
func NewHeadEncoder ¶
func NewHeadEncoder(fx HeadEncodeHandler) HeadEncoder
NewHeadEncoder provides a nice way of build an http headers encoders
type JSON ¶
JSON provides a basic json messages
func JSONRender ¶
JSONRender returns a json struct for rendering
type Message ¶
type Message struct { Queries url.Values MessageType string Method string Payload []byte Form url.Values PostForm url.Values Multipart *multipart.Form Params Collector }
Message represent a message data
type PProf ¶
type PProf struct{}
PProf provide pprofile handlers
func NewPProf ¶
func NewPProf(r *ChainRouter) *PProf
NewPProf provides an instantiated endpoint for pprofiles
func (*PProf) Index ¶
func (p *PProf) Index(c *Context, next NextHandler)
Index provides the pprof Index endpoint
func (*PProf) Profile ¶
func (p *PProf) Profile(c *Context, next NextHandler)
Profile provides the pprof Profile endpoint
func (*PProf) Symbol ¶
func (p *PProf) Symbol(c *Context, next NextHandler)
Symbol provides the pprof Symbol endpoint
func (*PProf) Trace ¶
func (p *PProf) Trace(c *Context, next NextHandler)
Trace provides the pprof Trace endpoint
type PanicHandler ¶
type PanicHandler func(http.ResponseWriter, *http.Request, interface{})
PanicHandler provides a panic function type for requests
type RHandler ¶
type RHandler func(http.ResponseWriter, *http.Request, Collector)
RHandler provides a custom route handler for http request with params
func BuildMatchesMethod ¶
BuildMatchesMethod returns RHandler which matches the methods of a request to a list of accepted methods to decided wether to run a RHandler function
func FSHandler ¶
func FSHandler(fs *FS, fail http.HandlerFunc) RHandler
FSHandler returns a valid Route.RHandler for use with the relay.Route
func FSServe ¶
func FSServe(fs http.FileSystem, stripPrefix string, fail http.HandlerFunc) RHandler
FSServe provides a http.Handler for serving using a http.FileSystem
func WrapRouteHandler ¶
WrapRouteHandler wraps http handler into a router RHandler
func WrapRouteHandlerFunc ¶
func WrapRouteHandlerFunc(r http.HandlerFunc) RHandler
WrapRouteHandlerFunc wraps http handler into a router RHandler
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher http.Hijacker // http.CloseNotifier Status() int Size() int Written() bool WritePayload(int, []byte) error }
ResponseWriter provides a clean interface decorated over the http.ResponseWriter
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) ResponseWriter
NewResponseWriter returns a new responseWriter
type SocketCodec ¶
type SocketCodec interface { Encoder SocketDecoder }
SocketCodec provides a interface define method for custom message formats
func NewSocketCodec ¶
func NewSocketCodec(e Encoder, d SocketDecoder) SocketCodec
NewSocketCodec returns a new http codec
type SocketDecodeHandler ¶
SocketDecodeHandler provides an handler for SocketEncoder
type SocketDecoder ¶
SocketDecoder decodes a WebsocketMessage
func NewSocketDecoder ¶
func NewSocketDecoder(fx SocketDecodeHandler) SocketDecoder
NewSocketDecoder provides a nice way of build an SocketDecoder
type SocketHandler ¶
type SocketHandler func(*SocketWorker)
SocketHandler provides an handler type without the port option
type SocketHub ¶
type SocketHub struct {
// contains filtered or unexported fields
}
SocketHub provides a central command for websocket message handling,its the base struct through which different websocket messaging procedures can be implemented on, it provides a go-routine approach,by taking each new websocket connection,stashing it then receiving data from it for processing
func NewSocketHub ¶
func NewSocketHub(fx SocketHubHandler) (sh *SocketHub)
NewSocketHub returns a new SocketHub instance,allows the passing of a codec for encoding and decoding data
func (*SocketHub) AddConnection ¶
func (s *SocketHub) AddConnection(ws *SocketWorker)
AddConnection adds a new socket connection
func (*SocketHub) CloseNotify ¶
CloseNotify provides a means of checking the close state of the hub
func (*SocketHub) Distribute ¶
func (s *SocketHub) Distribute(hsx SocketWorkerHandler, except *SocketWorker)
Distribute propagates through the set of defined websocket workers and calls a function on it
type SocketHubHandler ¶
type SocketHubHandler func(*SocketHub, *WebsocketMessage)
SocketHubHandler provides a function type that encapsulates the socket hub message operations
type SocketStore ¶
type SocketStore map[*SocketWorker]bool
SocketStore provides a map store for SocketHub
type SocketWorker ¶
type SocketWorker struct {
// contains filtered or unexported fields
}
SocketWorker provides a workpool for socket connections
func NewSocketWorker ¶
func NewSocketWorker(wo *Websocket) *SocketWorker
NewSocketWorker returns a new socketworker instance
func (*SocketWorker) Close ¶
func (s *SocketWorker) Close() error
Close closes the socket read goroutine and notifies a closure using the close channel
func (*SocketWorker) CloseNotify ¶
func (s *SocketWorker) CloseNotify() chan bool
CloseNotify returns a chan that is used to notify closing of socket
func (*SocketWorker) Equals ¶
func (s *SocketWorker) Equals(b interface{}) bool
Equals returns true/false if interface matches
func (*SocketWorker) Messages ¶
func (s *SocketWorker) Messages() <-chan *WebsocketMessage
Messages returns a receive only channel for socket messages
func (*SocketWorker) Socket ¶
func (s *SocketWorker) Socket() *Websocket
Socket returns the internal socket for the worker
type SocketWorkerHandler ¶
type SocketWorkerHandler func(*SocketWorker)
SocketWorkerHandler provides a function type that encapsulates the socket workers
type StringEachfunc ¶
type StringEachfunc func(interface{}, string, func())
StringEachfunc defines the type of the Mappable.Each rule
type SyncCollector ¶
type SyncCollector struct {
// contains filtered or unexported fields
}
SyncCollector provides a mutex controlled map
func NewSyncCollector ¶
func NewSyncCollector() *SyncCollector
NewSyncCollector returns a new collector instance
func (*SyncCollector) Clone ¶
func (c *SyncCollector) Clone() *SyncCollector
Clone makes a new clone of this collector
func (*SyncCollector) Copy ¶
func (c *SyncCollector) Copy(m map[string]interface{})
Copy copies the map into the collector
func (*SyncCollector) Each ¶
func (c *SyncCollector) Each(fx StringEachfunc)
Each iterates through all items in the collector
func (*SyncCollector) Get ¶
func (c *SyncCollector) Get(k string) interface{}
Get returns the value with the key
func (*SyncCollector) HasMatch ¶
func (c *SyncCollector) HasMatch(k string, v interface{}) bool
HasMatch checks if key and value exists and are matching
func (*SyncCollector) Keys ¶
func (c *SyncCollector) Keys() []string
Keys return the keys of the Collector
func (*SyncCollector) Remove ¶
func (c *SyncCollector) Remove(k string)
Remove deletes a key:value pair
func (*SyncCollector) Set ¶
func (c *SyncCollector) Set(k string, v interface{})
Set puts a specific key:value into the collector
func (*SyncCollector) ToMap ¶
func (c *SyncCollector) ToMap() map[string]interface{}
ToMap makes a new clone of this map[string]interface{}
type TCPKeepAliveListener ¶
type TCPKeepAliveListener struct {
*net.TCPListener
}
TCPKeepAliveListener provides the same internal wrapping as http keep alive functionalities
func KeepAliveListener ¶
func KeepAliveListener(t *net.TCPListener) *TCPKeepAliveListener
KeepAliveListener returns a new TCPKeepAliveListener
type Text ¶
Text provides a basic text messages
func TextRender ¶
TextRender returns a text struct for rendering
type WebsocketMessage ¶
type WebsocketMessage struct { *Websocket Worker *SocketWorker // contains filtered or unexported fields }
WebsocketMessage provides small abstraction for processing a message
func (*WebsocketMessage) Message ¶
func (m *WebsocketMessage) Message() []byte
Message returns the data of the socket
func (*WebsocketMessage) MessageType ¶
func (m *WebsocketMessage) MessageType() int
MessageType returns the type of the message