Documentation ¶
Index ¶
- Variables
- type Config
- type ConnStats
- type Connection
- type ConnectionStatus
- type Metrics
- type Pool
- type PoolConfig
- type PoolSize
- type Server
- func (s *Server) HandleRegister() http.Handler
- func (s *Server) HandleRequest(name string) http.Handler
- func (s *Server) HandleStats(resp http.ResponseWriter, req *http.Request)
- func (s *Server) ProxyError(resp http.ResponseWriter, req *http.Request, err error, regFail string)
- func (s *Server) Shutdown()
- func (s *Server) StartDispatcher()
- type Stats
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Dispatchers uint `json:"dispatchers" toml:"dispatchers" yaml:"dispatchers" xml:"dispatchers"` Timeout time.Duration `json:"timeout" toml:"timeout" yaml:"timeout" xml:"timeout"` IdleTimeout time.Duration `json:"idleTimeout" toml:"idle_timeout" yaml:"idleTimeout" xml:"idle_timeout"` SecretKey string `json:"secretKey" toml:"secret_key" yaml:"secretKey" xml:"secret_key"` // IDHeader sets the upstream header to parse for a remote client. // Default behavior is to send requests to clients randomly. // If this value is set, requests can only be directed to clients by providing the client ID in this header. IDHeader string `json:"idHeader" toml:"id_header" yaml:"idHeader" xml:"id_header"` // If a KeyValidator method is provided, then Secretkey is ignored. // If the validator returns a string then all pool IDs become a // sha256 of that string and the client's generated or provided id. // See the NewPool function to see that in action. // This allows you to let clients provide their own ID, but a secure // access-ID is created with your provided seed to prevent hash collisions. KeyValidator func(context.Context, http.Header) (string, error) `json:"-" toml:"-" yaml:"-" xml:"-"` // Logger allows routing logs from this package to somewhere special. // If left nil logs are written to stdout. Logger mulch.Logger `json:"-" toml:"-" yaml:"-" xml:"-"` }
Config configures a Server.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection manages a single websocket connection from the peer. Supports multiple connections from a single peer at the same time (a pool).
func NewConnection ¶
func NewConnection(pool *Pool, sock *websocket.Conn) *Connection
NewConnection returns a new Connection. Each connection gets a go routine to read (wait for) messages.
func (*Connection) Give ¶
func (c *Connection) Give()
Give a connection back to the idle buffer pool. Signals that this connection is ready to be used again. This gets called when an http request has completed.
func (*Connection) Status ¶
func (c *Connection) Status() ConnectionStatus
func (*Connection) Take ¶
func (c *Connection) Take() *Connection
Take notifies that this connection is going to be used. Returns nil if the connection is busy. This gets called at the beginning of an http request.
type ConnectionStatus ¶
type ConnectionStatus int
ConnectionStatus is an enumeration that represents the status of WebSocket connection.
const ( // Idle state means it is opened but not doing work now. // The default value for Connection is Idle. Idle ConnectionStatus = iota Busy // Unavailable for use. Closed // Never use again. )
func (ConnectionStatus) String ¶
func (c ConnectionStatus) String() string
type Metrics ¶
type Metrics struct { Uptime prometheus.CounterFunc Pools prometheus.Gauge Conns *prometheus.GaugeVec Regs *prometheus.CounterVec PoolConns *prometheus.GaugeVec // contains filtered or unexported fields }
Metrics contains the exported application metrics in prometheus format.
type Pool ¶
Pool handles all connections from the peer. Each pool is unique by it's clientID.
func NewPool ¶
func NewPool(server *Server, client *PoolConfig, altID string) *Pool
NewPool creates a new Pool, and starts one go routine per pool to keep it clean and running. Each pool represents 1 client, and each client may have many connections.
type PoolConfig ¶
type PoolConfig struct { *mulch.Handshake Sock *websocket.Conn // contains filtered or unexported fields }
PoolConfig is a struct for transitting a new pool's data through a channel.
type PoolSize ¶
type PoolSize struct { Total int `json:"total"` Idle int `json:"idle"` Busy int `json:"busy"` Closed int `json:"closed"` Conns []*ConnStats `json:"conns"` }
PoolSize is the number of connection in each state in the pool.
type Server ¶
type Server struct { Config *Config // contains filtered or unexported fields }
Server is a Reverse HTTP Proxy over WebSocket. This is the Server part, Clients offer websocket connections, and those are pooled to transfer HTTP Requests and responses.
func (*Server) HandleRegister ¶
HandleRegister receives http requests for /register paths. Receives the WebSocket upgrade handshake request from clients.
func (*Server) HandleRequest ¶
HandleRequest receives http requests for /request paths.
func (*Server) HandleStats ¶
func (s *Server) HandleStats(resp http.ResponseWriter, req *http.Request)
func (*Server) ProxyError ¶
ProxyError log error and return a HTTP 526 error with the message.
func (*Server) StartDispatcher ¶
func (s *Server) StartDispatcher()
StartDispatcher dispatches connections from available pools to client requests. You need to start this in a go routine.