types

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 17 Imported by: 9

Documentation

Index

Constants

View Source
const MinRead = 512

MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.

Variables

View Source
var ErrTooLarge = errors.New("bytes.Buffer: too large")

ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.

Functions

func IndexByte

func IndexByte(b []byte, c byte) int

IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.

func MiddlewareWrapper

func MiddlewareWrapper(options *Cors) func(*HttpContext, Callable)

Types

type Buffer

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

A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.

func NewBuffer

func NewBuffer(buf []byte) *Buffer

NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

func NewBufferString

func NewBufferString(s string) *Buffer

NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns a slice of length b.Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like Read, Write, Reset, or Truncate). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.

func (*Buffer) Grow

func (b *Buffer) Grow(n int)

Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (byte, error)

ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.

func (*Buffer) ReadRune

func (b *Buffer) ReadRune() (r rune, size int, err error)

ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1.

func (*Buffer) ReadString

func (b *Buffer) ReadString(delim byte) (line string, err error)

ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0).

func (*Buffer) Seek

func (b *Buffer) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface.

func (*Buffer) Size

func (b *Buffer) Size() int64

Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.

func (*Buffer) String

func (b *Buffer) String() string

String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".

To build strings more efficiently, see the strings.Builder type.

func (*Buffer) Truncate

func (b *Buffer) Truncate(n int)

Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It panics if n is negative or greater than the length of the buffer.

func (*Buffer) UnreadByte

func (b *Buffer) UnreadByte() error

UnreadByte unreads the last byte returned by the most recent successful read operation that read at least one byte. If a write has happened since the last read, if the last read returned an error, or if the read read zero bytes, UnreadByte returns an error.

func (*Buffer) UnreadRune

func (b *Buffer) UnreadRune() error

UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a successful ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge.

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) (n int, err error)

WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (n int, err error)

WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge.

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.

type BufferInterface

type BufferInterface interface {
	io.ReadWriteSeeker
	io.ReaderFrom
	io.WriterTo
	io.ByteScanner
	io.ByteWriter
	io.RuneScanner
	io.StringWriter
	WriteRune(rune) (int, error)
	Bytes() []byte
	fmt.Stringer
	Len() int
	Size() int64
	Cap() int
	Truncate(int)
	Reset()
	Grow(int)
	Next(int) []byte
	ReadBytes(byte) ([]byte, error)
	ReadString(byte) (string, error)
}

func NewBytesBuffer

func NewBytesBuffer(buf []byte) BufferInterface

func NewBytesBufferReader added in v1.0.9

func NewBytesBufferReader(r io.Reader) (BufferInterface, error)

func NewBytesBufferString

func NewBytesBufferString(s string) BufferInterface

func NewStringBuffer

func NewStringBuffer(buf []byte) BufferInterface

func NewStringBufferReader added in v1.0.9

func NewStringBufferReader(r io.Reader) (BufferInterface, error)

func NewStringBufferString

func NewStringBufferString(s string) BufferInterface

type BytesBuffer

type BytesBuffer struct {
	*Buffer
}

bytes buffer

type Callable

type Callable func()
var Noop Callable = func() {}

Noop function.

type CodeMessage

type CodeMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
}

type Cors

type Cors struct {
	Origin               interface{} `json:"origin,omitempty"`
	Methods              interface{} `json:"methods,omitempty"`
	AllowedHeaders       interface{} `json:"allowedHeaders,omitempty"`
	Headers              interface{} `json:"headers,omitempty"`
	ExposedHeaders       interface{} `json:"exposedHeaders,omitempty"`
	MaxAge               string      `json:"maxAge,omitempty"`
	Credentials          bool        `json:"credentials,omitempty"`
	PreflightContinue    bool        `json:"preflightContinue,omitempty"`
	OptionsSuccessStatus int         `json:"optionsSuccessStatus,omitempty"`
}

type ErrorMessage

type ErrorMessage struct {
	*CodeMessage

	Req     *HttpContext           `json:"req,omitempty"`
	Context map[string]interface{} `json:"context,omitempty"`
}

type HttpCompression

type HttpCompression struct {
	Threshold int `json:"threshold,omitempty"`
}

type HttpContext

type HttpContext struct {
	events.EventEmitter

	Websocket *WebSocketConn

	Cleanup Callable
	// contains filtered or unexported fields
}

func NewHttpContext

func NewHttpContext(w http.ResponseWriter, r *http.Request) *HttpContext

func (*HttpContext) Context

func (c *HttpContext) Context() context.Context

func (*HttpContext) Done

func (c *HttpContext) Done() <-chan struct{}

func (*HttpContext) Get

func (c *HttpContext) Get(key string, _default ...string) string

func (*HttpContext) GetHost

func (c *HttpContext) GetHost() (string, error)

func (*HttpContext) GetMethod

func (c *HttpContext) GetMethod() string

func (*HttpContext) GetPathInfo

func (c *HttpContext) GetPathInfo() string

func (*HttpContext) Gets

func (c *HttpContext) Gets(key string, _default ...[]string) []string

func (*HttpContext) Headers

func (c *HttpContext) Headers() *http.Header

func (*HttpContext) IsDone

func (c *HttpContext) IsDone() bool

func (*HttpContext) Method

func (c *HttpContext) Method() string

func (*HttpContext) Path

func (c *HttpContext) Path() string

func (*HttpContext) Query

func (c *HttpContext) Query() *utils.ParameterBag

func (*HttpContext) Request

func (c *HttpContext) Request() *http.Request

func (*HttpContext) Response

func (c *HttpContext) Response() http.ResponseWriter

func (*HttpContext) Secure

func (c *HttpContext) Secure() bool

func (*HttpContext) SetStatusCode

func (c *HttpContext) SetStatusCode(statusCode int)

func (*HttpContext) UserAgent

func (c *HttpContext) UserAgent() string

func (*HttpContext) Write

func (c *HttpContext) Write(wb []byte) (int, error)

type HttpServer

type HttpServer struct {
	events.EventEmitter
	*ServeMux
	// contains filtered or unexported fields
}

func CreateServer

func CreateServer(defaultHandler http.Handler) *HttpServer

func (*HttpServer) Close added in v1.0.8

func (s *HttpServer) Close(fn Callable) error

func (*HttpServer) Listen

func (s *HttpServer) Listen(addr string, fn Callable) *HttpServer

func (*HttpServer) ListenTLS

func (s *HttpServer) ListenTLS(addr string, certFile string, keyFile string, fn Callable) *HttpServer

type Kv

type Kv struct {
	Key   string
	Value string
}

type PerMessageDeflate

type PerMessageDeflate struct {
	Threshold int `json:"threshold,omitempty"`
}

type ServeMux added in v1.0.8

type ServeMux struct {
	DefaultHandler http.Handler // Default Handler
	// contains filtered or unexported fields
}

func NewServeMux added in v1.0.8

func NewServeMux(defaultHandler http.Handler) *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle added in v1.0.8

func (mux *ServeMux) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern. If a handler already exists for pattern, Handle panics.

func (*ServeMux) HandleFunc added in v1.0.8

func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*ServeMux) Handler added in v1.0.8

func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)

Handler returns the handler to use for the given request, consulting r.Method, r.Host, and r.URL.Path. It always returns a non-nil handler. If the path is not in its canonical form, the handler will be an internally-generated handler that redirects to the canonical path. If the host contains a port, it is ignored when matching handlers.

The path and host are used unchanged for CONNECT requests.

Handler also returns the registered pattern that matches the request or, in the case of internally-generated redirects, the pattern that will match after following the redirect.

If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.

func (*ServeMux) ServeHTTP added in v1.0.8

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable](keys ...T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(keys ...T) bool

func (*Set[T]) All

func (s *Set[T]) All() map[T]Void

func (*Set[T]) Clear

func (s *Set[T]) Clear() bool

func (*Set[T]) Delete added in v1.0.6

func (s *Set[T]) Delete(keys ...T) bool

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

func (*Set[T]) Keys

func (s *Set[T]) Keys() (list []T)

func (*Set[T]) Len added in v1.0.7

func (s *Set[T]) Len() int

type StringBuffer

type StringBuffer struct {
	*Buffer
}

string buffer

func (*StringBuffer) MarshalJSON added in v1.0.10

func (sb *StringBuffer) MarshalJSON() ([]byte, error)

MarshalJSON returns sb as the JSON encoding of m.

type Void

type Void struct{}
var NULL Void

type WebSocketConn

type WebSocketConn struct {
	events.EventEmitter
	*websocket.Conn
}

Jump to

Keyboard shortcuts

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