srv

package module
v0.0.0-...-f0d6e44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

srv

unit tests

The srv package provides middleware support for TCP/IP socket connections.

Install

go get ctx.sh/srv

Documentation

Index

Constants

View Source
const (
	PollTime time.Duration = 100 * time.Microsecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeTCP(ResponseWriter, *Request)
}

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

func (HandlerFunc) ServeTCP

func (f HandlerFunc) ServeTCP(w ResponseWriter, r *Request)

type Limiter

type Limiter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(size int32) *Limiter

func (*Limiter) Add

func (l *Limiter) Add()

func (*Limiter) Remove

func (l *Limiter) Remove()

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

func (MiddlewareFunc) Middleware

func (mw MiddlewareFunc) Middleware(handler Handler) Handler

type Request

type Request struct {
	Reader  bufio.Reader
	Context context.Context
	Data    interface{}
}

func (*Request) Read

func (r *Request) Read() ([]byte, error)

type ResponseWriter

type ResponseWriter interface {
	Write([]byte) (int, error)
}

type Route

type Route struct {
	// contains filtered or unexported fields
}

func (*Route) Handle

func (r *Route) Handle(handler Handler) *Route

func (*Route) HandleFunc

func (r *Route) HandleFunc(f func(ResponseWriter, *Request)) *Route

type Router

type Router struct {
	// TODO: MaxConnections is the number of incoming connections the server can
	// handle.  It is used to calculate the connection pool size.
	MaxConnections int32
	// TODO: Basecontext is unused in the router implementation. It was added to
	// mimic the server struct.
	BaseContext context.Context
	// TODO: ReadTimeout is unused in the router implementation.  It was added to
	// mimic the server struct.
	ReadTimeout time.Duration
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Handle

func (rt *Router) Handle(handler Handler) *Route

func (*Router) HandleFunc

func (rt *Router) HandleFunc(f func(w ResponseWriter, r *Request)) *Route

func (*Router) NewRoute

func (rt *Router) NewRoute() *Route

func (*Router) ServeTCP

func (rt *Router) ServeTCP(w ResponseWriter, r *Request)

func (*Router) Use

func (rt *Router) Use(mwf ...MiddlewareFunc)

type Server

type Server struct {
	MaxConnections int32
	BaseContext    context.Context
	ReadTimeout    time.Duration
	// contains filtered or unexported fields
}

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(network string, addr string, handler Handler) error

type Writer

type Writer struct {
	Connection net.Conn
	Data       interface{}
}

func (Writer) Write

func (w Writer) Write(b []byte) (n int, err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL