Documentation ¶
Overview ¶
Package server implements all methods required to process messages.
Index ¶
- Constants
- Variables
- func WSBinanceHandler(s *Server, w *WSConnection, msg []byte) error
- func WSDebugHandler(s *Server, w *WSConnection, msg []byte) error
- func WSTinkoffHandler(s *Server, w *WSConnection, msg []byte) error
- type Backend
- type BinanceCandle
- type BinanceError
- type BinanceKline
- type BinanceMessage
- type BinanceOrderBook
- type BinanceResult
- type Candle
- type GRPCConfig
- type Header
- type HealthStatus
- type LoggerConfig
- type MessageHeader
- type MonitorConfig
- type NATSConfig
- type Quote
- type Server
- func (s *Server) CloseNATS()
- func (s *Server) Debugf(format string, v ...any)
- func (s *Server) Errorf(format string, v ...any)
- func (s *Server) GRPCConfig() GRPCConfig
- func (s *Server) HandleLivez(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleNATSError(err error)
- func (s *Server) HandleReadyz(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleSignals()
- func (s *Server) IsNATSReconnecting() bool
- func (s *Server) IsRunning() bool
- func (s *Server) IsShutdown() bool
- func (s *Server) LoggerConfig() LoggerConfig
- func (s *Server) MonitorConfig() MonitorConfig
- func (s *Server) NATSConfig() NATSConfig
- func (s *Server) NATSSend(subject string, object interface{})
- func (s *Server) Noticef(format string, v ...any)
- func (s *Server) ProcessCandle(name string, c *Candle) error
- func (s *Server) ProcessQuote(name string, c *Quote) error
- func (s *Server) ResponseHandler(w http.ResponseWriter, r *http.Request, code int, data interface{})
- func (s *Server) ServerConfig() ServerConfig
- func (s *Server) Shutdown()
- func (s *Server) Start() error
- func (s *Server) StartGRPC() error
- func (s *Server) StartMonitor()
- func (s *Server) StartNATS()
- func (s *Server) StartWS(conn *WSConnection)
- func (s *Server) WSHandleError(conn *WSConnection, err error)
- func (s *Server) WSKeepAlive(cfg WSConfig, c *websocket.Conn)
- func (s *Server) WaitForShutdown()
- func (s *Server) Warnf(format string, v ...any)
- type ServerConfig
- type TinkoffCandle
- type TinkoffError
- type TinkoffEvent
- type TinkoffOrderBook
- type WSConfig
- type WSConnection
- type WSMsgHandler
Constants ¶
const ( LivezEndpoint = "/livez" ReadyzEndpoint = "/readyz" )
Variables ¶
var (
ErrServerShutdown = errors.New("server was shutdown or already started")
)
var (
Handlers = map[string]WSMsgHandler{}
)
Functions ¶
func WSBinanceHandler ¶
func WSBinanceHandler(s *Server, w *WSConnection, msg []byte) error
WSBinanceHandler process message from the binance stream.
func WSDebugHandler ¶
func WSDebugHandler(s *Server, w *WSConnection, msg []byte) error
WSDebugHandler just prints received message.
func WSTinkoffHandler ¶
func WSTinkoffHandler(s *Server, w *WSConnection, msg []byte) error
WSTinkoffHandler handles messages from tinkoff.
Types ¶
type Backend ¶
type Backend struct { pb.UnimplementedMonitorServer // contains filtered or unexported fields }
Backend is used to implement pb.Monitor.
type BinanceCandle ¶
type BinanceCandle struct { EventType string `json:"e"` EventTime int64 `json:"E"` Symbol string `json:"s"` Kline BinanceKline `json:"k"` }
type BinanceError ¶
type BinanceKline ¶
type BinanceKline struct { StartTime int64 `json:"t"` EndTime int64 `json:"T"` Symbol string `json:"s"` Interval string `json:"i"` FirstTradeID int64 `json:"f"` LastTradeID int64 `json:"L"` Open string `json:"o"` Close string `json:"c"` High string `json:"h"` Low string `json:"l"` Volume string `json:"v"` TradeNum int64 `json:"n"` IsFinal bool `json:"x"` QuoteVolume string `json:"q"` ActiveBuyVolume string `json:"V"` ActiveBuyQuoteVolume string `json:"Q"` Ignore string `json:"B"` }
type BinanceMessage ¶
type BinanceOrderBook ¶
type BinanceResult ¶
type BinanceResult struct { Result *interface{} `json:"result"` ID int `json:"id"` }
type Candle ¶
type Candle struct { MessageHeader Interval string `json:"interval"` Open string `json:"open"` High string `json:"high"` Low string `json:"low"` Close string `json:"close"` Volume string `json:"volume"` }
func (*Candle) NATSSubject ¶
NATSSubject returns the subject for the candle message
type GRPCConfig ¶
type GRPCConfig struct { Bind string `xml:"Bind"` TLS bool `xml:"TLS"` TLSCertificate string `xml:"TLSCertificate"` TLSKey string `xml:"TLSKey"` }
GRPC Configuration
func DefaultGRPCConfig ¶
func DefaultGRPCConfig() GRPCConfig
DefaultGRPCConfig returns default GRPC config
type HealthStatus ¶
HealthStatus represents server health status.
type LoggerConfig ¶
type LoggerConfig struct {
Debug bool `xml:"Debug"`
}
Logger Configuration
func DefaultLoggerConfig ¶
func DefaultLoggerConfig() LoggerConfig
DefaultLoggerConfig returns default Logger config.
type MessageHeader ¶
type MessageHeader struct { Symbol string `json:"symbol"` Source string `json:"source"` Time int64 `json:"time"` TimeSrv int64 `json:"time_srv"` TimeRcv int64 `json:"time_rcv"` }
MessageHeader represents common fields for each message
type MonitorConfig ¶
type MonitorConfig struct { Bind string `xml:"Bind"` TLS bool `xml:"TLS"` TLSCertificate string `xml:"TLSCertificate"` TLSKey string `xml:"TLSKey"` Headers []Header `xml:"Header"` }
Monitor Configuration
func DefaultMonitorConfig ¶
func DefaultMonitorConfig() MonitorConfig
DefaultMonitorConfig returns default Monitor config
type NATSConfig ¶
type NATSConfig struct { Name string `xml:"Name"` URL string `xml:"URL"` RetryDelay int `xml:"RetryDelay"` NoReconnect bool `xml:"NoReconnect"` }
NATS Configuration
func DefaultNATSConfig ¶
func DefaultNATSConfig() NATSConfig
DefaultNATSConfig returns default NATS config
func (*NATSConfig) NATSOptions ¶
func (c *NATSConfig) NATSOptions() []nats.Option
NATSOptions returns a list of NATS connection options.
type Quote ¶
type Quote struct { MessageHeader BidsDepth int `json:"bids_depth"` Bids [][]string `json:"bids"` AsksDepth int `json:"asks_depth"` Asks [][]string `json:"asks"` }
func (*Quote) NATSSubject ¶
NATSSubject returns the subject for the candle message
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(config ServerConfig) (*Server, error)
NewServer will setup a new server instance struct.
func (*Server) GRPCConfig ¶
func (s *Server) GRPCConfig() GRPCConfig
GRPCConfig returns GRPC configuration.
func (*Server) HandleLivez ¶
func (s *Server) HandleLivez(w http.ResponseWriter, r *http.Request)
HandleLivez returns liveness check.
func (*Server) HandleNATSError ¶
HandleNATSError handles NATS errors.
func (*Server) HandleReadyz ¶
func (s *Server) HandleReadyz(w http.ResponseWriter, r *http.Request)
HandleReadyz returns readiness check.
func (*Server) HandleSignals ¶
func (s *Server) HandleSignals()
HandleSignals runs a goroutine to handle signals.
func (*Server) IsNATSReconnecting ¶
IsNATSReconnecting returns whether NATS is scheduled to reconnect.
func (*Server) IsShutdown ¶
IsShutdown returns whether server is performing shutdown.
func (*Server) LoggerConfig ¶
func (s *Server) LoggerConfig() LoggerConfig
LoggerConfig returns Logger configuration.
func (*Server) MonitorConfig ¶
func (s *Server) MonitorConfig() MonitorConfig
MonitorConfig returns MonitorConfig.
func (*Server) NATSConfig ¶
func (s *Server) NATSConfig() NATSConfig
NATSConfig returns NATS configuration.
func (*Server) ProcessCandle ¶
ProcessCandle processes the candle.
func (*Server) ProcessQuote ¶
ProcessQuote processes the quote.
func (*Server) ResponseHandler ¶
func (s *Server) ResponseHandler(w http.ResponseWriter, r *http.Request, code int, data interface{})
ResponseHandler handles responses for monitor routes (JSONP and JSON).
func (*Server) ServerConfig ¶
func (s *Server) ServerConfig() ServerConfig
Config returns a copy of Server configuration.
func (*Server) StartMonitor ¶
func (s *Server) StartMonitor()
StartMonitor starts the HTTP or HTTPs server if needed.
func (*Server) StartWS ¶
func (s *Server) StartWS(conn *WSConnection)
StartWS establishes websocket connection.
func (*Server) WSHandleError ¶
func (s *Server) WSHandleError(conn *WSConnection, err error)
WSHandleError handles the error.
func (*Server) WSKeepAlive ¶
WSKeepAlive enabled Ping-Pong with given timeout.
func (*Server) WaitForShutdown ¶
func (s *Server) WaitForShutdown()
WaitForShutdown will block until the server has been fully shutdown.
type ServerConfig ¶
type ServerConfig struct { Logger LoggerConfig `xml:"Logger"` Monitor MonitorConfig `xml:"Monitor"` NATS NATSConfig `xml:"NATS"` GRPC GRPCConfig `xml:"GRPC"` WebSocket []WSConfig `xml:"WebSocket"` }
Server Configuration
type TinkoffCandle ¶
type TinkoffError ¶
type TinkoffEvent ¶
type TinkoffEvent struct { Event string `json:"event"` Time time.Time `json:"time"` Payload json.RawMessage `json:"payload"` }
type TinkoffOrderBook ¶
type WSConfig ¶
type WSConfig struct { Name string `xml:"Name"` Enabled bool `xml:"Enabled"` URL string `xml:"URL"` Handler string `xml:"Handler"` DialTimeout int `xml:"DialTimeout"` RetryDelay int `xml:"RetryDelay"` PingTimeout int `xml:"PingTimeout"` ReadLimit int64 `xml:"ReadLimit"` Headers []Header `xml:"Header"` InitMessages []string `xml:"InitMessage"` }
WebSocket Configuration
type WSConnection ¶
func (*WSConnection) IsWSReconnecting ¶
func (c *WSConnection) IsWSReconnecting() bool
IsWSReconnecting returns whether websocket is scheduled to reconnect.
type WSMsgHandler ¶
type WSMsgHandler func(s *Server, w *WSConnection, msg []byte) error