ev

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

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

Go to latest
Published: Dec 7, 2017 License: MIT Imports: 12 Imported by: 0

README

ev

A helper package to use github.com/tidwall/evio more easily

Dependencies
How To Use

See http example

TODO
  • Improve performance. Even with just wake up and immediately replying, it could only reach 17k rps on my machine (just like Node.JS 8.9.2) while with the http example, it averaged at 13k rps. I think this could be hard to do, the benchmark command I use is go-wrk -M POST -H 'Content-Type: application/json' -body '{"data":"ping"}' -c 10 -d 10 -T 500 http://localhost:5000 using go-wrk

  • Make this pluggable with Gin (I still don't know how to make http.ResponseWriter to feed Gin engine to)

  • Support TLS

Documentation

Index

Constants

View Source
const (
	DefaultTickDelayDuration   = time.Millisecond * 100
	InternalServerErrorMessage = "Internal server error: %s"
	BadRequestErrorMessage     = "Bad request: %s"
	ContentTypeTextPlain       = "text/plain"
	Separator                  = "\r\n\r\n"
)
View Source
const (
	MinimumHTTPStringFormat = "" /* 137-byte string literal not displayed */
)

Variables

View Source
var (
	ErrorMalformedBody   = errors.New("Malformed request body")
	ErrorMalformedHeader = errors.New("Malformed request header")

	ContentLengthRegexp = regexp.MustCompile("Content-Length: ([0-9]+)")
	HostPortOnlyRegexp  = regexp.MustCompile("^:[0-9]{1,5}$")
)
View Source
var (
	HTTPStringFormat = MinimumHTTPStringFormat
)

Functions

func GetHTTPRequest

func GetHTTPRequest(req []byte) (httpReq *http.Request, err error)

func NewRawHTTPResponse

func NewRawHTTPResponse(status int, contentType string, body []byte) (res []byte)

func SetHTTPStringFormat

func SetHTTPStringFormat(format string)

Types

type Conn

type Conn map[int]*ConnInfo

type ConnInfo

type ConnInfo struct {
	ID          int
	Input       []byte
	Output      []byte
	Info        evio.Info
	InputStream evio.InputStream
}

type DataHandlerFunc

type DataHandlerFunc func(connInfo *ConnInfo)

type Ev

type Ev struct {
	Server                         evio.Server
	Conn                           Conn
	Host                           string
	DataHandler                    DataHandlerFunc
	TickHandler                    TickHandlerFunc
	UnexpectedDisconnectionHandler UnexpectedDisconnectionFunc
	// contains filtered or unexported fields
}

func New

func New(host string, dataHandler DataHandlerFunc, tickHandler TickHandlerFunc, unexpectedDisconnectionHandler UnexpectedDisconnectionFunc) *Ev

func (*Ev) Listen

func (e *Ev) Listen() (err error)

func (*Ev) Shutdown

func (e *Ev) Shutdown()

type Queue

type Queue struct {
	ID       int
	ConnInfo *ConnInfo
}

type TickHandlerFunc

type TickHandlerFunc func() (delay time.Duration)

type UnexpectedDisconnectionFunc

type UnexpectedDisconnectionFunc func(connInfo *ConnInfo)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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