server

package
v0.0.0-...-ca736ed Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTemplates

func ParseTemplates(_path string) *template.Template

func SetHeaders

func SetHeaders(w http.ResponseWriter)

Types

type ApiHandler

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

type Client

type Client struct {
	Server *Server

	// The websocket connection.
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the node.

func NewClient

func NewClient(server *Server, conn *websocket.Conn) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetSend

func (c *Client) GetSend() chan *Message

func (*Client) IsClosed

func (c *Client) IsClosed(ch <-chan *Message) bool

func (*Client) Listen

func (c *Client) Listen()

func (*Client) NewMessage

func (c *Client) NewMessage() *Message

func (*Client) Send

func (c *Client) Send(message *Message)

func (*Client) SendBytes

func (c *Client) SendBytes(payload []byte)

func (*Client) SendString

func (c *Client) SendString(payload string)

type Command

type Command struct {
	Name    string `json:"name"`
	Payload string `json:"payload"`
}

type Message

type Message struct {
	Payload []byte
	Client  *Client
}

func NewMessage

func NewMessage(client *Client, payload []byte) *Message

func (*Message) Decode

func (m *Message) Decode(v interface{}) bool

func (*Message) Encode

func (m *Message) Encode(v interface{}) bool

func (*Message) Send

func (m *Message) Send()

type RateLimit

type RateLimit struct {
	Limit    rate.Limit
	Burst    int
	Interval time.Duration
	Mutex    *sync.RWMutex
	Visitors map[string]*Visitor
}

func NewRateLimit

func NewRateLimit(limit int, burst int, interval time.Duration) *RateLimit

func (*RateLimit) AddIP

func (i *RateLimit) AddIP(ip string) *rate.Limiter

AddIP creates a new rate limiter and adds it to the ips map, using the IP address as the key

func (*RateLimit) GetLimiter

func (i *RateLimit) GetLimiter(ip string) *rate.Limiter

GetLimiter returns the rate limiter for the provided IP address if it exists. Otherwise calls AddIP to add IP address to the map

type Server

type Server struct {
	Config  *config.Config
	Counter *counter.Counter

	Host string
	Port int

	RateLimit *RateLimit
	Visitors  map[string]*Visitor

	Upgrader websocket.Upgrader

	Api *ApiHandler
	// contains filtered or unexported fields
}

func NewServerConfig

func NewServerConfig(c *config.Config, assets *assetfs.AssetFS) *Server

func (*Server) NewHandler

func (s *Server) NewHandler() (http.Handler, error)

func (*Server) Start

func (s *Server) Start()

type Visitor

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

Create a custom visitor struct which holds the rate limiter for each visitor and the last time that the visitor was seen.

Jump to

Keyboard shortcuts

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