tcpGateway

package
v0.5.28 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const MethodWild = "*"

MethodWild wild HTTP method

Variables

View Source
var (
	ErrUnsupportedProtocol  = errors.New("gateway protocol is not supported")
	ErrWriteToClosedConn    = errors.New("write to closed conn")
	ErrUnexpectedSocketRead = errors.New("unexpected socket read")
	ErrOpCloseReceived      = errors.New("close operation received")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Concurrency   int
	ListenAddress string
	MaxBodySize   int
	MaxIdleTime   time.Duration
	Protocol      gateway.Protocol
	ExternalAddrs []string
	Mux           *Mux
}

Config

type Gateway

type Gateway struct {
	gateway.ConnectHandler
	gateway.MessageHandler
	gateway.CloseHandler
	// contains filtered or unexported fields
}

Gateway

func MustNew

func MustNew(config Config) *Gateway

func New

func New(config Config) (*Gateway, error)

New

func (*Gateway) Addr

func (g *Gateway) Addr() []string

Addr return the address which gateway is listen on

func (*Gateway) GetConn

func (g *Gateway) GetConn(connID uint64) rony.Conn

GetConn returns the connection identified by connID

func (*Gateway) Run

func (g *Gateway) Run()

Run is blocking and runs the server endless loop until a non-temporary error happens

func (*Gateway) Shutdown

func (g *Gateway) Shutdown()

Shutdown

func (*Gateway) Start

func (g *Gateway) Start()

Start is non-blocking and call the Run function in background

func (*Gateway) TotalConnections

func (g *Gateway) TotalConnections() int

type Mux added in v0.5.23

type Mux struct {

	// Enables automatic redirection if the current route can't be matched but a
	// handler for the path with (without) the trailing slash exists.
	// For example if /foo/ is requested but a route only exists for /foo, the
	// client is redirected to /foo with http status code 301 for GET requests
	// and 308 for all other request methods.
	RedirectTrailingSlash bool

	// If enabled, the router tries to fix the current request path, if no
	// handle is registered for it.
	// First superfluous path elements like ../ or // are removed.
	// Afterwards the router does a case-insensitive lookup of the cleaned path.
	// If a handle can be found for this route, the router makes a redirection
	// to the corrected path with status code 301 for GET requests and 308 for
	// all other request methods.
	// For example /FOO and /..//Foo could be redirected to /foo.
	// RedirectTrailingSlash is independent of this option.
	RedirectFixedPath bool

	// If enabled, the router checks if another method is allowed for the
	// current route, if the current request can not be routed.
	// If this is the case, the request is answered with 'Method Not Allowed'
	// and HTTP status code 405.
	// If no other Method is allowed, the request is delegated to the NotFound
	// handler.
	HandleMethodNotAllowed bool

	// If enabled, the router automatically replies to OPTIONS requests.
	// Custom OPTIONS handlers take priority over automatic replies.
	HandleOPTIONS bool

	// An optional gateway.MuxHandler that is called on automatic OPTIONS requests.
	// The handler is only called if HandleOPTIONS is true and no OPTIONS
	// handler for the specific path was set.
	// The "Allowed" header is set before calling the handler.
	GlobalOPTIONS gateway.MuxHandler

	// Configurable gateway.MuxHandler which is called when no matching route is
	// found. If it is not set, default NotFound is used.
	NotFound gateway.MuxHandler

	// Configurable MuxHandler which is called when a request
	// cannot be routed and HandleMethodNotAllowed is true.
	// If it is not set, ctx.Error with fasthttp.StatusMethodNotAllowed is used.
	// The "Allow" header with allowed request methods is set before the handler
	// is called.
	MethodNotAllowed gateway.MuxHandler
	// contains filtered or unexported fields
}

func NewMux added in v0.5.23

func NewMux() *Mux

func (*Mux) Handle added in v0.5.23

func (r *Mux) Handle(method, path string, handler gateway.MuxHandler)

Handle registers a new request handler with the given path and method.

For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func (*Mux) List added in v0.5.23

func (r *Mux) List() map[string][]string

List returns all registered routes grouped by method

type UnsafeConn

type UnsafeConn interface {
	net.Conn
	UnsafeConn() net.Conn
}

Directories

Path Synopsis
Package wsutil provides utilities for working with WebSocket protocol.
Package wsutil provides utilities for working with WebSocket protocol.

Jump to

Keyboard shortcuts

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