Documentation
¶
Index ¶
Constants ¶
View Source
const ( B = 1 << (10 * iota) KB MB GB TB PB EB )
Byte unit helpers.
Variables ¶
View Source
var ErrServerStopped = errors.New("ktcp: the server has been stopped")
ErrServerStopped is returned when server stopped.
View Source
var ErrSessionClosed = fmt.Errorf("session closed")
ErrSessionClosed is returned when session stopped.
Functions ¶
func NewContext ¶ added in v0.0.2
func NewContext() *routerCtx
Types ¶
type Context ¶
type Context interface {
context.Context
GetSession() *Session
ForwardHandler(c CallBack)
GetReqMsg() *message.Message
Bind(v interface{}) error
Response() *message.Message
Send(id uint32, resp interface{}) error
SendError(id uint32, resp interface{}) error
Middleware(middleware.Handler) middleware.Handler
Reset(sess *Session, reqMsg *message.Message)
AppendToStorage(saver storage.Saver)
Save() (err error)
}
Context is a generic context in a message routing. It allows us to pass variables between handler and middlewares.
type Server ¶
type Server struct {
Listener net.Listener
Packer packing.Packer // Packer is the message packer, will be passed to session.
Codec encoding.Codec // Codec is the message codec, will be passed to session.
// contains filtered or unexported fields
}
Server is a server for TCP connections.
func NewServer ¶
func NewServer(handler Handler, opts ...ServerOption) *Server
NewServer creates an TCP server by options.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an HTTP server option.
func Middleware ¶
func Middleware(m ...middleware.Middleware) ServerOption
Middleware with service middleware option.
func ReadTimeout ¶
func ReadTimeout(readTimeout time.Duration) ServerOption
ReadTimeout with server timeout.
func WriteTimeout ¶
func WriteTimeout(writeTimeout time.Duration) ServerOption
WriteTimeout with server timeout.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a server side network connection.
func (*Session) Close ¶
func (s *Session) Close()
Close closes the session, but doesn't close the connection.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
protoc-gen-go-errors
module
|
|
|
protoc-gen-go-ktcp
module
|
|
|
proto
Package proto defines the protobuf codec.
|
Package proto defines the protobuf codec. |
|
example
|
|
|
simple/client
command
|
|
|
simple/server
command
|
|
|
internal
|
|
|
sync
|
|
|
errgroup
Package errgroup provides synchronization, error propagation, and Context errgroup 包为一组子任务的 goroutine 提供了 goroutine 同步,错误取消功能.
|
Package errgroup provides synchronization, error propagation, and Context errgroup 包为一组子任务的 goroutine 提供了 goroutine 同步,错误取消功能. |
Click to show internal directories.
Click to hide internal directories.