Documentation ¶
Index ¶
- Constants
- Variables
- func NewContextFromSession(parent context.Context, sess *Session) context.Context
- type ConnectionHandler
- type ContextKey
- type Error
- type HandlerFunc
- type Message
- type Server
- type Session
- type SessionManager
- func (m *SessionManager) Add(sess *Session)
- func (m *SessionManager) Count() int
- func (m *SessionManager) ListAll() []*Session
- func (m *SessionManager) Start()
- func (m *SessionManager) Stop()
- func (m *SessionManager) Terminate(sess *Session) error
- func (m *SessionManager) TerminateAll(ctx context.Context) (err error)
- type SessionTerminatedEvent
- type StatusCode
- type StatusError
Constants ¶
View Source
const ( ServerStatusInitial int32 = iota ServerStatusStarted ServerStatusStopped )
Variables ¶
View Source
var (
NilError = &StatusError{Code: StatusOK, message: "OK"}
)
Functions ¶
Types ¶
type ConnectionHandler ¶
type ConnectionHandler struct { Handler HandlerFunc // Connection handler SessManager *SessionManager // Session manager Codec *proto.Codec // Protocol codec }
func NewConnectionHandler ¶
func NewConnectionHandler( h HandlerFunc, mgr *SessionManager, codec *proto.Codec) *ConnectionHandler
type Error ¶
Error represents a handler error. It provides methods for a server status code and embeds the built-in error interface.
type Message ¶
func NewMessage ¶
func NewMessageWithError ¶
func (*Message) ProtoMessage ¶
ProtoMessage adapts into a protobuf response message.
type Server ¶
type Server struct { *ConnectionHandler // Connection handler // contains filtered or unexported fields }
func NewTCPServer ¶
func NewTCPServer(addr string, ch *ConnectionHandler) (srv *Server, err error)
func NewUDPServer ¶
func NewUDPServer(addr string, ch *ConnectionHandler) (srv *Server, err error)
type Session ¶
type Session struct { ID string // Session ID Conn net.Conn // Underlying network connection // contains filtered or unexported fields }
func NewSession ¶
func (*Session) LastActive ¶
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager() *SessionManager
func (*SessionManager) Add ¶
func (m *SessionManager) Add(sess *Session)
func (*SessionManager) Count ¶
func (m *SessionManager) Count() int
func (*SessionManager) ListAll ¶
func (m *SessionManager) ListAll() []*Session
func (*SessionManager) Start ¶
func (m *SessionManager) Start()
Start function to start checking for timeouts periodically
func (*SessionManager) Stop ¶
func (m *SessionManager) Stop()
Stop function to stop checking for timeouts
func (*SessionManager) Terminate ¶
func (m *SessionManager) Terminate(sess *Session) error
func (*SessionManager) TerminateAll ¶
func (m *SessionManager) TerminateAll(ctx context.Context) (err error)
type SessionTerminatedEvent ¶
type SessionTerminatedEvent struct {
Sess *Session
}
type StatusCode ¶
type StatusCode = int32
const ( StatusOK StatusCode = iota StatusInternalServerError StatusBadRequest )
type StatusError ¶
StatusError represents an error with an associated server status code.
func NewBadRequestError ¶
func NewBadRequestError(err error) *StatusError
func NewInternalServerError ¶
func NewInternalServerError(err error) *StatusError
func (*StatusError) Error ¶
func (se *StatusError) Error() string
Allows StatusError to satisfy the error interface.
Click to show internal directories.
Click to hide internal directories.