fibre

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

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

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 24 Imported by: 4

README

fibre

A simple and fast http framework for Go (Golang).

Features
  • Simple and efficient router
  • Extensible middleware framework
  • Customise when middleware should run
  • Built to run with REST or Websockets
  • Build APIs with RESTful methodologies
  • Build APIs with Websocket methodologies
  • Build APIs with JSONRpc methodologies
  • Centralized and customisable error logging
  • Works seamlessly with Golang's standard HTTP server
  • Automatic data binding for Form, XML, JSON, CBOR, MsgPack
  • Automatic response type detection for XML, JSON, CBOR, MsgPack
Installation
go get github.com/surrealdb/fibre

Documentation

Index

Constants

View Source
const (
	// HEAD ...
	HEAD = "HEAD"
	// GET ...
	GET = "GET"
	// PUT ...
	PUT = "PUT"
	// POST ...
	POST = "POST"
	// PATCH ...
	PATCH = "PATCH"
	// TRACE ...
	TRACE = "TRACE"
	// DELETE ...
	DELETE = "DELETE"
	// OPTIONS ...
	OPTIONS = "OPTIONS"
	// CONNECT ...
	CONNECT = "CONNECT"
)
View Source
const (
	HeaderAccept              = "Accept"
	HeaderAcceptEncoding      = "Accept-Encoding"
	HeaderAllow               = "Allow"
	HeaderAuthenticate        = "WWW-Authenticate"
	HeaderAuthorization       = "Authorization"
	HeaderContentDisposition  = "Content-Disposition"
	HeaderContentEncoding     = "Content-Encoding"
	HeaderContentLength       = "Content-Length"
	HeaderContentType         = "Content-Type"
	HeaderCookie              = "Cookie"
	HeaderIfModifiedSince     = "If-Modified-Since"
	HeaderLastModified        = "Last-Modified"
	HeaderLocation            = "Location"
	HeaderOrigin              = "Origin"
	HeaderServer              = "Server"
	HeaderSetCookie           = "Set-Cookie"
	HeaderUpgrade             = "Upgrade"
	HeaderVary                = "Vary"
	HeaderXForwardedFor       = "X-Forwarded-For"
	HeaderXForwardedProto     = "X-Forwarded-Proto"
	HeaderXForwardedProtocol  = "X-Forwarded-Protocol"
	HeaderXForwardedSsl       = "X-Forwarded-Ssl"
	HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
	HeaderXPoweredBy          = "X-Powered-By"
	HeaderXRealIP             = "X-Real-IP"
	HeaderXRequestID          = "X-Request-ID"
	HeaderXUrlScheme          = "X-Url-Scheme"

	// Access control
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"

	// Security
	HeaderContentSecurityPolicy   = "Content-Security-Policy"
	HeaderPublicKeyPins           = "Public-Key-Pins"
	HeaderStrictTransportSecurity = "Strict-Transport-Security"
	HeaderXContentTypeOptions     = "X-Content-Type-Options"
	HeaderXCSRFToken              = "X-CSRF-Token"
	HeaderXFrameOptions           = "X-Frame-Options"
	HeaderXXSSProtection          = "X-XSS-Protection"
)

Variables

View Source
var MiddlewareSkip = func(h HandlerFunc) HandlerFunc {
	return func(c *Context) error {
		return h(c)
	}
}

Functions

This section is empty.

Types

type Client

type Client struct {
	*websocket.Conn
}

Socket wraps an websocket.Conn

func NewClient

func NewClient(url string, protocols []string) (*Client, error)

NewClient creates a new instance of Response.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Read

func (c *Client) Read() (int, []byte, error)

Read reads a message from the socket.

func (*Client) ReadCBOR

func (c *Client) ReadCBOR(v interface{}) (err error)

ReadCBOR reads a cbor message from the socket.

func (*Client) ReadJSON

func (c *Client) ReadJSON(v interface{}) (err error)

ReadJSON reads a json message from the socket.

func (*Client) ReadPACK

func (c *Client) ReadPACK(v interface{}) (err error)

ReadPACK reads a msgpack message from the socket.

func (*Client) ReadXML

func (c *Client) ReadXML(v interface{}) (err error)

ReadXML reads a xml message from the socket.

func (*Client) Rpc

func (c *Client) Rpc() (chan<- *RPCRequest, <-chan *RPCResponse, chan error)

func (*Client) Send

func (c *Client) Send(t int, data []byte) (err error)

Send sends a response to the socket.

func (*Client) SendCBOR

func (c *Client) SendCBOR(data interface{}) (err error)

SendCBOR sends a cbor response with status code.

func (*Client) SendJSON

func (c *Client) SendJSON(data interface{}) (err error)

SendJSON sends a json response with status code.

func (*Client) SendPACK

func (c *Client) SendPACK(data interface{}) (err error)

SendPACK sends a msgpack response with status code.

func (*Client) SendText

func (c *Client) SendText(data string) (err error)

SendText sends a text response with status code.

func (*Client) SendXML

func (c *Client) SendXML(data interface{}) (err error)

SendXML sends a xml response with status code.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context represents context for the current request.

func NewContext

func NewContext(req *Request, res *Response, f *Fibre) *Context

NewContext creates a Context object.

func (*Context) Bind

func (c *Context) Bind(i interface{}) (err error)

Bind decodes the request body into the object.

func (*Context) Body

func (c *Context) Body() []byte

Body returns the full content body.

func (*Context) CBOR

func (c *Context) CBOR(code int, data interface{}) (err error)

CBOR sends a cbor response with status code.

func (*Context) Code

func (c *Context) Code(code int) (err error)

Code sends a http response status code.

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Data

func (c *Context) Data(code int, data interface{}, mime string) (err error)

Data sends a response with status code and mime type.

func (*Context) Error

func (c *Context) Error(err error)

Error invokes the registered HTTP error handler. Generally used by middleware.

func (*Context) Fibre

func (c *Context) Fibre() *Fibre

Fibre returns the fibre instance.

func (*Context) File

func (c *Context) File(path string) (err error)

File sends a response with the content of a file.

func (*Context) Form

func (c *Context) Form(name string) (v string)

Form returns form parameter by name.

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get retrieves data from the context.

func (*Context) HTML

func (c *Context) HTML(code int, data interface{}) (err error)

HTML sends an html response with status code.

func (*Context) Head

func (c *Context) Head() map[string]string

Head returns the processed headers.

func (*Context) IP

func (c *Context) IP() net.IP

IP returns the ip address belonging to this context.

func (*Context) IsComplete

func (c *Context) IsComplete() bool

IsComplete returns true if the response has been closed.

func (*Context) IsOrigin

func (c *Context) IsOrigin() bool

IsOrigin returns true if the request specifies an origin.

func (*Context) IsSocket

func (c *Context) IsSocket() bool

IsSocket returns true if the request is made over WebSocket.

func (*Context) IsTLS

func (c *Context) IsTLS() bool

IsTLS returns true if the request was made over TLS.

func (*Context) JSON

func (c *Context) JSON(code int, data interface{}) (err error)

JSON sends a json response with status code.

func (*Context) Origin

func (c *Context) Origin() (v string)

Origin returns the request origin if specified.

func (*Context) PACK

func (c *Context) PACK(code int, data interface{}) (err error)

PACK sends a msgpack response with status code.

func (*Context) Param

func (c *Context) Param(name string) (v string)

Param returns path parameter by name.

func (*Context) Path

func (c *Context) Path() string

Path returns the registered path for the handler.

func (*Context) Query

func (c *Context) Query(name string) (v string)

Query returns query parameter by name.

func (*Context) Redirect

func (c *Context) Redirect(code int, url string) (err error)

Redirect redirects the http request to a different url.

func (*Context) Request

func (c *Context) Request() *Request

Request returns the http request object.

func (*Context) Response

func (c *Context) Response() *Response

Response returns the http response object.

func (*Context) Send

func (c *Context) Send(code int, data interface{}) (err error)

Send sends the relevant response depending on the request type.

func (*Context) Set

func (c *Context) Set(key string, val interface{})

Set saves data in the context.

func (*Context) Socket

func (c *Context) Socket() *Socket

Socket returns the websocket connection.

func (*Context) Text

func (c *Context) Text(code int, data interface{}) (err error)

Text sends a text response with status code.

func (*Context) Type

func (c *Context) Type() string

Type returns the desired response mime type.

func (*Context) Uniq

func (c *Context) Uniq() string

func (*Context) Upgrade

func (c *Context) Upgrade(protocols ...string) (err error)

Upgrade upgrades the http request to a websocket connection.

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context) *Context

func (*Context) XML

func (c *Context) XML(code int, data interface{}) (err error)

XML sends a xml response with status code.

type Fibre

type Fibre struct {
	// contains filtered or unexported fields
}

Fibre represents an HTTP server

func Server

func Server() (f *Fibre)

Server creates a new server instance.

func (*Fibre) Any

func (f *Fibre) Any(p string, h HandlerFunc)

Any adds a route > handler to the router for all HTTP methods.

func (*Fibre) Connect

func (f *Fibre) Connect(p string, h HandlerFunc)

Connect adds a CONNECT route > handler to the router.

func (*Fibre) Delete

func (f *Fibre) Delete(p string, h HandlerFunc)

Delete adds a DELETE route > handler to the router.

func (*Fibre) Dir

func (f *Fibre) Dir(p, dir string)

Dir serves a folder.

func (*Fibre) File

func (f *Fibre) File(p, file string)

File serves a file.

func (*Fibre) Get

func (f *Fibre) Get(p string, h HandlerFunc)

Get adds a GET route > handler to the router.

func (*Fibre) Head

func (f *Fibre) Head(p string, h HandlerFunc)

Head adds a HEAD route > handler to the router.

func (*Fibre) Logger

func (f *Fibre) Logger() *Logger

Logger returns the logger instance.

func (*Fibre) Name

func (f *Fibre) Name() string

Name returns the instance name.

func (*Fibre) Options

func (f *Fibre) Options(p string, h HandlerFunc)

Options adds an OPTIONS route > handler to the router.

func (*Fibre) Patch

func (f *Fibre) Patch(p string, h HandlerFunc)

Patch adds a PATCH route > handler to the router.

func (*Fibre) Post

func (f *Fibre) Post(p string, h HandlerFunc)

Post adds a POST route > handler to the router.

func (*Fibre) Pprof

func (f *Fibre) Pprof()

func (*Fibre) Put

func (f *Fibre) Put(p string, h HandlerFunc)

Put adds a PUT route > handler to the router.

func (*Fibre) Router

func (f *Fibre) Router() *Router

Router returns the router instance.

func (*Fibre) Rpc

func (f *Fibre) Rpc(p string, i interface{})

Rpc adds a route > handler to the router for a jsonrpc endpoint.

func (*Fibre) Run

func (f *Fibre) Run(a string, files ...string)

Run runs the server and handles http requests.

func (*Fibre) ServeHTTP

func (f *Fibre) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements `http.Handler` interface, which serves HTTP requests.

func (*Fibre) SetHTTPErrorHandler

func (f *Fibre) SetHTTPErrorHandler(h HTTPErrorHandler)

SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.

func (*Fibre) SetIdleTimeout

func (f *Fibre) SetIdleTimeout(wait string)

SetIdleTimeout sets the max idle time for a keepalive connection.

func (*Fibre) SetLogFormat

func (f *Fibre) SetLogFormat(l string)

SetLogFormat sets the logger log format.

func (*Fibre) SetLogLevel

func (f *Fibre) SetLogLevel(l string)

SetLogLevel sets the logger log level.

func (*Fibre) SetName

func (f *Fibre) SetName(name string)

SetName sets the instance name.

func (*Fibre) SetReadTimeout

func (f *Fibre) SetReadTimeout(wait string)

SetReadTimeout sets the max duration for reading requests.

func (*Fibre) SetWriteTimeout

func (f *Fibre) SetWriteTimeout(wait string)

SetWriteTimeout sets the max duration for writing responses.

func (*Fibre) Trace

func (f *Fibre) Trace(p string, h HandlerFunc)

Trace adds a TRACE route > handler to the router.

func (*Fibre) Use

Use adds a middleware function

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

HTTPError represents an error that occurred while handling a request.

func NewHTTPError

func NewHTTPError(code int, message ...string) (err *HTTPError)

NewHTTPError creates a new instance of HTTPError.

func (*HTTPError) Code

func (e *HTTPError) Code() int

Code returns code.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns message.

func (*HTTPError) Fields

func (e *HTTPError) Fields() map[string]interface{}

Fields returns error fields.

func (*HTTPError) WithField

func (e *HTTPError) WithField(k string, v interface{}) *HTTPError

func (*HTTPError) WithFields

func (e *HTTPError) WithFields(f map[string]interface{}) *HTTPError

func (*HTTPError) WithMessage

func (e *HTTPError) WithMessage(m string) *HTTPError

type HTTPErrorHandler

type HTTPErrorHandler func(error, *Context)

HTTPErrorHandler is a centralized HTTP error handler.

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc represents a request handler

type Logger

type Logger struct {
	*logrus.Logger
}

Logger ...

func NewLogger

func NewLogger(f *Fibre) *Logger

NewLogger returns a new Logger instance.

func (*Logger) SetFormat

func (l *Logger) SetFormat(v string)

SetFormat sets the logging format.

func (*Logger) SetLevel

func (l *Logger) SetLevel(v string)

SetLevel sets the logging level.

func (*Logger) SetLogger

func (l *Logger) SetLogger(i *logrus.Logger)

SetLogger sets the logrus instance.

type Middleware

type Middleware []MiddlewareFunc

Middleware stores loaded middleware

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc represents a request middleware

func (MiddlewareFunc) AgentBegsWith

func (m MiddlewareFunc) AgentBegsWith(tests ...string) MiddlewareFunc

AgentBegsWith checks if the request agent begins with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) AgentEndsWith

func (m MiddlewareFunc) AgentEndsWith(tests ...string) MiddlewareFunc

AgentEndsWith checks if the request agent ends with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) AgentIs

func (m MiddlewareFunc) AgentIs(tests ...string) MiddlewareFunc

AgentIs checks if the request agent is exactly equal to a value, and if it is then the middleware will be invoked.

func (MiddlewareFunc) AgentIsNot

func (m MiddlewareFunc) AgentIsNot(tests ...string) MiddlewareFunc

AgentIsNot checks if the request agent is not exactly equal to a value, and if it isn't then the middleware will be invoked.

func (MiddlewareFunc) AgentMatches

func (m MiddlewareFunc) AgentMatches(tests ...regexp.Regexp) MiddlewareFunc

AgentMatches checks if the request agent matches a regular expression, and if it does then the middleware will be invoked.

func (MiddlewareFunc) HostBegsWith

func (m MiddlewareFunc) HostBegsWith(tests ...string) MiddlewareFunc

HostBegsWith checks if the request host begins with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) HostEndsWith

func (m MiddlewareFunc) HostEndsWith(tests ...string) MiddlewareFunc

HostEndsWith checks if the request host ends with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) HostIs

func (m MiddlewareFunc) HostIs(tests ...string) MiddlewareFunc

HostIs checks if the request host is exactly equal to a value, and if it is then the middleware will be invoked.

func (MiddlewareFunc) HostIsNot

func (m MiddlewareFunc) HostIsNot(tests ...string) MiddlewareFunc

HostIsNot checks if the request host is not exactly equal to a value, and if it isn't then the middleware will be invoked.

func (MiddlewareFunc) HostMatches

func (m MiddlewareFunc) HostMatches(tests ...regexp.Regexp) MiddlewareFunc

HostMatches checks if the request host matches a regular expression, and if it does then the middleware will be invoked.

func (MiddlewareFunc) MethodBegsWith

func (m MiddlewareFunc) MethodBegsWith(tests ...string) MiddlewareFunc

MethodBegsWith checks if the request method begins with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) MethodEndsWith

func (m MiddlewareFunc) MethodEndsWith(tests ...string) MiddlewareFunc

MethodEndsWith checks if the request method ends with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) MethodIs

func (m MiddlewareFunc) MethodIs(tests ...string) MiddlewareFunc

MethodIs checks if the request method is exactly equal to a value, and if it is then the middleware will be invoked.

func (MiddlewareFunc) MethodIsNot

func (m MiddlewareFunc) MethodIsNot(tests ...string) MiddlewareFunc

MethodIsNot checks if the request method is not exactly equal to a value, and if it isn't then the middleware will be invoked.

func (MiddlewareFunc) MethodMatches

func (m MiddlewareFunc) MethodMatches(tests ...regexp.Regexp) MiddlewareFunc

MethodMatches checks if the request method matches a regular expression, and if it does then the middleware will be invoked.

func (MiddlewareFunc) PathBegsWith

func (m MiddlewareFunc) PathBegsWith(tests ...string) MiddlewareFunc

PathBegsWith checks if the request oath begins with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) PathEndsWith

func (m MiddlewareFunc) PathEndsWith(tests ...string) MiddlewareFunc

PathEndsWith checks if the request oath ends with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) PathIs

func (m MiddlewareFunc) PathIs(tests ...string) MiddlewareFunc

PathIs checks if the request oath is exactly equal to a value, and if it is then the middleware will be invoked.

func (MiddlewareFunc) PathIsNot

func (m MiddlewareFunc) PathIsNot(tests ...string) MiddlewareFunc

PathIsNot checks if the request oath is not exactly equal to a value, and if it isn't then the middleware will be invoked.

func (MiddlewareFunc) PathMatches

func (m MiddlewareFunc) PathMatches(tests ...regexp.Regexp) MiddlewareFunc

PathMatches checks if the request oath matches a regular expression, and if it does then the middleware will be invoked.

func (MiddlewareFunc) SchemeBegsWith

func (m MiddlewareFunc) SchemeBegsWith(tests ...string) MiddlewareFunc

SchemeBegsWith checks if the request scheme begins with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) SchemeEndsWith

func (m MiddlewareFunc) SchemeEndsWith(tests ...string) MiddlewareFunc

SchemeEndsWith checks if the request scheme ends with a value, and if it does then the middleware will be invoked.

func (MiddlewareFunc) SchemeIs

func (m MiddlewareFunc) SchemeIs(tests ...string) MiddlewareFunc

SchemeIs checks if the request scheme is exactly equal to a value, and if it is then the middleware will be invoked.

func (MiddlewareFunc) SchemeIsNot

func (m MiddlewareFunc) SchemeIsNot(tests ...string) MiddlewareFunc

SchemeIsNot checks if the request scheme is not exactly equal to a value, and if it isn't then the middleware will be invoked.

func (MiddlewareFunc) SchemeMatches

func (m MiddlewareFunc) SchemeMatches(tests ...regexp.Regexp) MiddlewareFunc

SchemeMatches checks if the request scheme matches a regular expression, and if it does then the middleware will be invoked.

type RPCError

type RPCError struct {
	Code    int    `json:"code" msgpack:"code"`
	Message string `json:"message,omitempty" msgpack:"message,omitempty"`
}

RPCError represents a jsonrpc error

func (*RPCError) Error

func (r *RPCError) Error() string

type RPCNotification

type RPCNotification struct {
	ID     interface{}   `json:"id" msgpack:"id"`
	Method string        `json:"method,omitempty" msgpack:"method,omitempty"`
	Params []interface{} `json:"params,omitempty" msgpack:"params,omitempty"`
}

RPCNotification represents an outgoing jsonrpc notification

type RPCNull

type RPCNull struct{}

RPCNull represents a null argument

type RPCRequest

type RPCRequest struct {
	ID     interface{}   `json:"id" msgpack:"id"`
	Async  bool          `json:"async,omitempty" msgpack:"async,omitempty"`
	Method string        `json:"method,omitempty" msgpack:"method,omitempty"`
	Params []interface{} `json:"params,omitempty" msgpack:"params,omitempty"`
}

RPCRequest represents an incoming jsonrpc request

type RPCResponse

type RPCResponse struct {
	ID     interface{} `json:"id" msgpack:"id"`
	Error  *RPCError   `json:"error,omitempty" msgpack:"error,omitempty"`
	Result interface{} `json:"result,omitempty" msgpack:"result,omitempty"`
}

RPCResponse represents an outgoing jsonrpc response

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request wraps an http.Request

func NewRequest

func NewRequest(i *http.Request, f *Fibre) *Request

NewRequest creates a new instance of Response.

func (*Request) Header

func (r *Request) Header() http.Header

Header returns the header map values for this Request,

func (*Request) Reader

func (r *Request) Reader() *http.Request

Reader returns the http.Request instance for this Request.

func (*Request) SetReader

func (r *Request) SetReader(w *http.Request)

SetReader sets the http.Request instance for this Request.

func (*Request) Size

func (r *Request) Size() int64

Size returns the current size, in bytes, of the request.

func (*Request) Start

func (r *Request) Start() time.Time

Start returns the current size, in bytes, of the request.

func (*Request) URL

func (r *Request) URL() *URL

URL returns the parsed url of the request.

type Response

type Response struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Response wraps an http.Response

func NewResponse

func NewResponse(i http.ResponseWriter, f *Fibre) *Response

NewResponse creates a new instance of Response.

func (*Response) CloseNotify

func (r *Response) CloseNotify() <-chan bool

CloseNotify enables detecting when the underlying connection has gone away.

func (*Response) Done

func (r *Response) Done() bool

Done asserts whether or not the response has been sent.

func (*Response) Flush

func (r *Response) Flush()

Flush enables buffered data using http.Flusher.

func (*Response) Header

func (r *Response) Header() http.Header

Header returns the header map values for this Response.

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack enabled connection hijacking using http.Hijacker.

func (*Response) SetWriter

func (r *Response) SetWriter(w http.ResponseWriter)

SetWriter sets the http.ResponseWriter instance for this Response.

func (*Response) Size

func (r *Response) Size() int64

Size returns the current size, in bytes, of the response.

func (*Response) Status

func (r *Response) Status() int

Status returns the HTTP status code of the response.

func (*Response) Write

func (r *Response) Write(b []byte) (n int, err error)

Write wraps and implements the http.Response.Write specification.

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.

func (*Response) Writer

func (r *Response) Writer() http.ResponseWriter

Writer returns the http.ResponseWriter instance for this Response.

type Route

type Route struct {
	Rank    int
	Path    string
	Method  string
	Handler HandlerFunc
}

Route stores a handler for matching paths against requests.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router stores routes used in request matching and handler dispatching.

func NewRouter

func NewRouter(f *Fibre) *Router

NewRouter returns a new Router instance.

func (*Router) Add

func (r *Router) Add(meth, path string, hand HandlerFunc)

Add registers a new route with a matcher for the URL path.

func (*Router) Find

func (r *Router) Find(meth, path string, ctx *Context) (hand HandlerFunc)

Find dispatches the request to the handler whose path and method match

type Socket

type Socket struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

Socket wraps an websocket.Conn

func NewSocket

func NewSocket(i *websocket.Conn, c *Context, f *Fibre) *Socket

NewSocket creates a new instance of Response.

func (*Socket) Close

func (s *Socket) Close(code int) error

func (*Socket) Notify

func (s *Socket) Notify(val *RPCNotification)

func (*Socket) Read

func (s *Socket) Read() (int, []byte, error)

Read reads a message from the socket.

func (*Socket) ReadCBOR

func (s *Socket) ReadCBOR(v interface{}) (err error)

ReadCBOR reads a cbor message from the socket.

func (*Socket) ReadJSON

func (s *Socket) ReadJSON(v interface{}) (err error)

ReadJSON reads a json message from the socket.

func (*Socket) ReadPACK

func (s *Socket) ReadPACK(v interface{}) (err error)

ReadPACK reads a msgpack message from the socket.

func (*Socket) ReadXML

func (s *Socket) ReadXML(v interface{}) (err error)

ReadXML reads a xml message from the socket.

func (*Socket) Send

func (s *Socket) Send(t int, data []byte) (err error)

Send sends a response to the socket.

func (*Socket) SendCBOR

func (s *Socket) SendCBOR(data interface{}) (err error)

SendCBOR sends a cbor response with status code.

func (*Socket) SendJSON

func (s *Socket) SendJSON(data interface{}) (err error)

SendJSON sends a json response with status code.

func (*Socket) SendPACK

func (s *Socket) SendPACK(data interface{}) (err error)

SendPACK sends a msgpack response with status code.

func (*Socket) SendText

func (s *Socket) SendText(data string) (err error)

SendText sends a text response with status code.

func (*Socket) SendXML

func (s *Socket) SendXML(data interface{}) (err error)

SendXML sends a xml response with status code.

type URL

type URL struct {
	Scheme   string
	User     string
	Pass     string
	Host     string
	Path     string
	Query    string
	Fragment string
}

URL defines a parsed url

func NewURL

func NewURL(tls bool, uri string) *URL

NewURL parses and returns a new URL object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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