Documentation ¶
Index ¶
- func InitLogger(config *ServerConfig)
- func New(ctx ...interface{}) log15.Logger
- func NewCORSMiddleware(options CORS) gin.HandlerFunc
- func RootHandler() log15.Handler
- 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 Tendermint
- 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
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 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 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, error)
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 { ChainId string Bind Bind `toml:"bind"` TLS TLS `toml:"TLS"` CORS CORS `toml:"CORS"` HTTP HTTP `toml:"HTTP"` WebSocket WebSocket `toml:"web_socket"` Tendermint Tendermint Logging Logging `toml:"logging"` }
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
NOTE: [ben] only preserved for /test/server tests; but should not be used and will be deprecated.
func ReadServerConfig ¶
func ReadServerConfig(viper *viper.Viper) (*ServerConfig, error)
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 uint16, 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 Tendermint ¶
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 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 uint16, 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.