Documentation ¶
Index ¶
- func InitLogger(config *ServerConfig)
- func New(ctx ...interface{}) log15.Logger
- func NewCORSMiddleware(options CORS) gin.HandlerFunc
- func RootHandler() log15.Handler
- func WriteServerConfig(filePath string, cfg *ServerConfig) error
- type Bind
- type CORS
- type HTTP
- type HttpService
- type IdPool
- type Logging
- type ServeProcess
- type Server
- type ServerConfig
- type SessionManager
- func (this *SessionManager) RemoveSessionCloseEventChannel(lChan chan *WSSession) bool
- func (this *SessionManager) RemoveSessionOpenEventChannel(lChan chan *WSSession) bool
- func (this *SessionManager) SessionCloseEventChannel() <-chan *WSSession
- func (this *SessionManager) SessionOpenEventChannel() <-chan *WSSession
- func (this *SessionManager) Shutdown()
- type SessionObserver
- type TLS
- type WSSession
- type WebSocket
- type WebSocketServer
- type WebSocketService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
func InitLogger(config *ServerConfig)
This is basically the same code as in tendermint. Initialize root and maybe later also track the loggers here.
func NewCORSMiddleware ¶
func NewCORSMiddleware(options CORS) gin.HandlerFunc
func WriteServerConfig ¶
func WriteServerConfig(filePath string, cfg *ServerConfig) error
Write a server configuration file.
Types ¶
type CORS ¶
type CORS struct { Enable bool `toml:"enable"` AllowOrigins []string `toml:"allow_origins"` AllowCredentials bool `toml:"allow_credentials"` AllowMethods []string `toml:"allow_methods"` AllowHeaders []string `toml:"allow_headers"` ExposeHeaders []string `toml:"expose_headers"` MaxAge uint64 `toml:"max_age"` }
Options stores configurations
type HTTP ¶
type HTTP struct {
JsonRpcEndpoint string `toml:"json_rpc_endpoint"`
}
Standard configuration file for the server.
type HttpService ¶
type HttpService interface {
Process(*http.Request, http.ResponseWriter)
}
type IdPool ¶
type IdPool struct {
// contains filtered or unexported fields
}
Simple id pool. Lets you get and release uints. Will panic if trying to get an id and it's empty.
type Logging ¶
type Logging struct { ConsoleLogLevel string `toml:"console_log_level"` FileLogLevel string `toml:"file_log_level"` LogFile string `toml:"log_file"` }
Standard configuration file for the server.
type ServeProcess ¶
type ServeProcess struct {
// contains filtered or unexported fields
}
The ServeProcess wraps all the Servers. Starting it will add all the server handlers to the router and start listening for incoming requests. There is also startup and shutdown events that can be listened to, on top of any events that the servers may have (the default websocket server has events for monitoring sessions. Startup event listeners should be added before calling 'Start()'. Stop event listeners can be added up to the point where the server is stopped and the event is fired.
func NewServeProcess ¶
func NewServeProcess(config *ServerConfig, servers ...Server) *ServeProcess
Creates a new serve process.
func (*ServeProcess) Start ¶
func (this *ServeProcess) Start() error
Initializes all the servers and starts listening for connections.
func (*ServeProcess) StartEventChannel ¶
func (this *ServeProcess) StartEventChannel() <-chan struct{}
Get a start-event channel from the server. The start event is fired after the Start() function is called, and after the server has started listening for incoming connections. An error here .
func (*ServeProcess) Stop ¶
func (this *ServeProcess) Stop(timeout time.Duration) error
Stop will release the port, process any remaining requests up until the timeout duration is passed, at which point it will abort them and shut down.
func (*ServeProcess) StopEventChannel ¶
func (this *ServeProcess) StopEventChannel() <-chan struct{}
Get a stop-event channel from the server. The event happens after the Stop() function has been called, and after the timeout has passed. When the timeout has passed it will wait for confirmation from the http.Server, which normally takes a very short time (milliseconds).
type Server ¶
type Server interface { Start(*ServerConfig, *gin.Engine) Running() bool ShutDown() }
A server serves a number of different http calls.
type ServerConfig ¶
type ServerConfig struct { Bind Bind `toml:"bind"` TLS TLS `toml:"TLS"` CORS CORS `toml:"CORS"` HTTP HTTP `toml:"HTTP"` WebSocket WebSocket `toml:"web_socket"` Logging Logging `toml:"logging"` }
Standard configuration file for the server.
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
func ReadServerConfig ¶
func ReadServerConfig(filePath string) (*ServerConfig, error)
Read a TOML server configuration file.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
Session manager handles the adding, tracking and removing of session objects.
func NewSessionManager ¶
func NewSessionManager(maxSessions uint, wss WebSocketService) *SessionManager
Create a new WebsocketManager.
func (*SessionManager) RemoveSessionCloseEventChannel ¶
func (this *SessionManager) RemoveSessionCloseEventChannel(lChan chan *WSSession) bool
Remove a listener from session close events.
func (*SessionManager) RemoveSessionOpenEventChannel ¶
func (this *SessionManager) RemoveSessionOpenEventChannel(lChan chan *WSSession) bool
Remove a listener from session open events.
func (*SessionManager) SessionCloseEventChannel ¶
func (this *SessionManager) SessionCloseEventChannel() <-chan *WSSession
Add a listener to session close events
func (*SessionManager) SessionOpenEventChannel ¶
func (this *SessionManager) SessionOpenEventChannel() <-chan *WSSession
Add a listener to session open events.
type SessionObserver ¶
Used to track sessions. Will notify when a session are opened and closed.
type TLS ¶
type TLS struct { TLS bool `toml:"tls"` CertPath string `toml:"cert_path"` KeyPath string `toml:"key_path"` }
Standard configuration file for the server.
type WSSession ¶
type WSSession struct {
// contains filtered or unexported fields
}
WSSession wraps a gorilla websocket.Conn, which in turn wraps a net.Conn object. Writing is done using the 'Write([]byte)' method, which passes the bytes on to the write pump over a channel.
func (*WSSession) Close ¶
func (this *WSSession) Close()
Closes the net connection and cleans up. Notifies all the observers.
type WebSocket ¶
type WebSocket struct { WebSocketEndpoint string `toml:"websocket_endpoint"` MaxWebSocketSessions uint `toml:"max_websocket_sessions"` ReadBufferSize uint `toml:"read_buffer_size"` WriteBufferSize uint `toml:"write_buffer_size"` }
Standard configuration file for the server.
type WebSocketServer ¶
type WebSocketServer struct {
// contains filtered or unexported fields
}
The websocket server handles incoming websocket connection requests, upgrading, reading, writing, and session management. Handling the actual requests is delegated to a websocket service.
func NewWebSocketServer ¶
func NewWebSocketServer(maxSessions uint, service WebSocketService) *WebSocketServer
Create a new server. maxSessions is the maximum number of active websocket connections that is allowed. NOTE: This is not the total number of connections allowed - only those that are upgraded to websockets. Requesting a websocket connection will fail with a 503 if the server is at capacity.
func (*WebSocketServer) Running ¶
func (this *WebSocketServer) Running() bool
Is the server currently running.
func (*WebSocketServer) SessionManager ¶
func (this *WebSocketServer) SessionManager() *SessionManager
Get the session-manager.
func (*WebSocketServer) Start ¶
func (this *WebSocketServer) Start(config *ServerConfig, router *gin.Engine)
Start the server. Adds the handler to the router and sets everything up.
type WebSocketService ¶
Services requests. Message bytes are passed along with the session object. The service is expected to write any response back using the Write function on WSSession, which passes the message over a channel to the write pump.