utils

package
v0.5.1-0...-5006072 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoArgValue = errors.New("no Args value for the given key")

ErrNoArgValue is returned when Args value with the given key is missing.

Functions

func AppendHTMLEscape

func AppendHTMLEscape(dst []byte, s string) []byte

AppendHTMLEscape appends html-escaped s to dst and returns the extended dst.

func AppendHTMLEscapeBytes

func AppendHTMLEscapeBytes(dst, s []byte) []byte

AppendHTMLEscapeBytes appends html-escaped s to dst and returns the extended dst.

func AppendHTTPDate

func AppendHTTPDate(dst []byte, date time.Time) []byte

AppendHTTPDate appends HTTP-compliant (RFC1123) representation of date to dst and returns the extended dst.

func AppendIPv4

func AppendIPv4(dst []byte, ip net.IP) []byte

AppendIPv4 appends string representation of the given ip v4 to dst and returns the extended dst.

func AppendQuotedArg

func AppendQuotedArg(dst, src []byte) []byte

AppendQuotedArg appends url-encoded src to dst and returns appended dst.

func AppendUint

func AppendUint(dst []byte, n int) []byte

AppendUint appends n to dst and returns the extended dst.

func ParseHTTPDate

func ParseHTTPDate(date []byte) (time.Time, error)

ParseHTTPDate parses HTTP-compliant (RFC1123) date.

func ParseIPv4

func ParseIPv4(dst net.IP, ipStr []byte) (net.IP, error)

ParseIPv4 parses ip address from ipStr into dst and returns the extended dst.

func ParseUfloat

func ParseUfloat(buf []byte) (float64, error)

ParseUfloat parses unsigned float from buf.

func ParseUint

func ParseUint(buf []byte) (int, error)

ParseUint parses uint from buf.

func ReleaseArgs

func ReleaseArgs(a *Args)

ReleaseArgs returns the object acquired via AquireArgs to the pool.

Do not access the released Args object, otherwise data races may occur.

func ReleaseByteBuffer

func ReleaseByteBuffer(b *ByteBuffer)

ReleaseByteBuffer returns byte buffer to the pool.

ByteBuffer.B mustn't be touched after returning it to the pool. Otherwise data races will occur.

Types

type Args

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

Args represents query arguments.

It is forbidden copying Args instances. Create new instances instead and use CopyTo().

Args instance MUST NOT be used from concurrently running goroutines.

func AcquireArgs

func AcquireArgs() *Args

AcquireArgs returns an empty Args object from the pool.

The returned Args may be returned to the pool with ReleaseArgs when no longer needed. This allows reducing GC load.

func (*Args) Add

func (a *Args) Add(key, value string)

Add adds 'key=value' argument.

Multiple values for the same key may be added.

func (*Args) AddBytesK

func (a *Args) AddBytesK(key []byte, value string)

AddBytesK adds 'key=value' argument.

Multiple values for the same key may be added.

func (*Args) AddBytesKV

func (a *Args) AddBytesKV(key, value []byte)

AddBytesKV adds 'key=value' argument.

Multiple values for the same key may be added.

func (*Args) AddBytesV

func (a *Args) AddBytesV(key string, value []byte)

AddBytesV adds 'key=value' argument.

Multiple values for the same key may be added.

func (*Args) AppendBytes

func (a *Args) AppendBytes(dst []byte) []byte

AppendBytes appends query string to dst and returns the extended dst.

func (*Args) CopyTo

func (a *Args) CopyTo(dst *Args)

CopyTo copies all args to dst.

func (*Args) Del

func (a *Args) Del(key string)

Del deletes argument with the given key from query args.

func (*Args) DelBytes

func (a *Args) DelBytes(key []byte)

DelBytes deletes argument with the given key from query args.

func (*Args) GetBool

func (a *Args) GetBool(key string) bool

GetBool returns boolean value for the given key.

true is returned for '1', 'y' and 'yes' values, otherwise false is returned.

func (*Args) GetUfloat

func (a *Args) GetUfloat(key string) (float64, error)

GetUfloat returns ufloat value for the given key.

func (*Args) GetUfloatOrZero

func (a *Args) GetUfloatOrZero(key string) float64

GetUfloatOrZero returns ufloat value for the given key.

Zero (0) is returned on error.

func (*Args) GetUint

func (a *Args) GetUint(key string) (int, error)

GetUint returns uint value for the given key.

func (*Args) GetUintOrZero

func (a *Args) GetUintOrZero(key string) int

GetUintOrZero returns uint value for the given key.

Zero (0) is returned on error.

func (*Args) Has

func (a *Args) Has(key string) bool

Has returns true if the given key exists in Args.

func (*Args) HasBytes

func (a *Args) HasBytes(key []byte) bool

HasBytes returns true if the given key exists in Args.

func (*Args) Len

func (a *Args) Len() int

Len returns the number of query args.

func (*Args) Parse

func (a *Args) Parse(s string)

Parse parses the given string containing query args.

func (*Args) ParseBytes

func (a *Args) ParseBytes(b []byte)

ParseBytes parses the given b containing query args.

func (*Args) Peek

func (a *Args) Peek(key string) []byte

Peek returns query arg value for the given key.

Returned value is valid until the next Args call.

func (*Args) PeekBytes

func (a *Args) PeekBytes(key []byte) []byte

PeekBytes returns query arg value for the given key.

Returned value is valid until the next Args call.

func (*Args) PeekMulti

func (a *Args) PeekMulti(key string) [][]byte

PeekMulti returns all the arg values for the given key.

func (*Args) PeekMultiBytes

func (a *Args) PeekMultiBytes(key []byte) [][]byte

PeekMultiBytes returns all the arg values for the given key.

func (*Args) QueryString

func (a *Args) QueryString() []byte

QueryString returns query string for the args.

The returned value is valid until the next call to Args methods.

func (*Args) Reset

func (a *Args) Reset()

Reset clears query args.

func (*Args) Set

func (a *Args) Set(key, value string)

Set sets 'key=value' argument.

func (*Args) SetBytesK

func (a *Args) SetBytesK(key []byte, value string)

SetBytesK sets 'key=value' argument.

func (*Args) SetBytesKV

func (a *Args) SetBytesKV(key, value []byte)

SetBytesKV sets 'key=value' argument.

func (*Args) SetBytesV

func (a *Args) SetBytesV(key string, value []byte)

SetBytesV sets 'key=value' argument.

func (*Args) SetUint

func (a *Args) SetUint(key string, value int)

SetUint sets uint value for the given key.

func (*Args) SetUintBytes

func (a *Args) SetUintBytes(key []byte, value int)

SetUintBytes sets uint value for the given key.

func (*Args) String

func (a *Args) String() string

String returns string representation of query args.

func (*Args) VisitAll

func (a *Args) VisitAll(f func(key, value []byte))

VisitAll calls f for each existing arg.

f must not retain references to key and value after returning. Make key and/or value copies if you need storing them after returning.

func (*Args) WriteTo

func (a *Args) WriteTo(w io.Writer) (int64, error)

WriteTo writes query string to w.

WriteTo implements io.WriterTo interface.

type BufferPool

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

Pool represents byte buffer pool.

Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.

func (*BufferPool) Get

func (p *BufferPool) Get() *ByteBuffer

Get returns new byte buffer with zero length.

The byte buffer may be returned to the pool via Put after the use in order to minimize GC overhead.

func (*BufferPool) Put

func (p *BufferPool) Put(b *ByteBuffer)

Put releases byte buffer obtained via Get to the pool.

The buffer mustn't be accessed after returning to the pool.

type BufioReader

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

func NewBufioReader

func NewBufioReader(r io.Reader, limit ...int64) *BufioReader

func NewBufioReaderSize

func NewBufioReaderSize(r io.Reader, size int, limit ...int64) *BufioReader

func (*BufioReader) Buffered

func (b *BufioReader) Buffered() int

func (*BufioReader) Count

func (b *BufioReader) Count() int64

func (*BufioReader) Discard

func (b *BufioReader) Discard(n int) (discarded int, err error)

func (*BufioReader) Read

func (b *BufioReader) Read(p []byte) (int, error)

func (*BufioReader) ReadByte

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

func (*BufioReader) Reset

func (b *BufioReader) Reset(r io.Reader)

func (*BufioReader) ResetCount

func (b *BufioReader) ResetCount()

func (*BufioReader) ResetLimit

func (b *BufioReader) ResetLimit(limit int64)

type BufioWriter

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

func NewBufioWriter

func NewBufioWriter(w io.Writer) *BufioWriter

func NewBufioWriterSize

func NewBufioWriterSize(w io.Writer, size int) *BufioWriter

func (*BufioWriter) Available

func (b *BufioWriter) Available() int

func (*BufioWriter) Buffered

func (b *BufioWriter) Buffered() int

func (*BufioWriter) Count

func (b *BufioWriter) Count() int64

func (*BufioWriter) Flush

func (b *BufioWriter) Flush() error

func (*BufioWriter) ReadFrom

func (b *BufioWriter) ReadFrom(r io.Reader) (int64, error)

func (*BufioWriter) Reset

func (b *BufioWriter) Reset(w io.Writer)

func (*BufioWriter) ResetCount

func (b *BufioWriter) ResetCount()

func (*BufioWriter) Write

func (b *BufioWriter) Write(p []byte) (int, error)

func (*BufioWriter) WriteByte

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

func (*BufioWriter) WriteRune

func (b *BufioWriter) WriteRune(r rune) (int, error)

func (*BufioWriter) WriteString

func (b *BufioWriter) WriteString(s string) (int, error)

type ByteBuffer

type ByteBuffer struct {

	// B is a byte buffer to use in append-like workloads.
	// See example code for details.
	B []byte
}

ByteBuffer provides byte buffer, which can be used for minimizing memory allocations.

ByteBuffer may be used with functions appending data to the given []byte slice. See example code for details.

Use Get for obtaining an empty byte buffer.

func AcquireByteBuffer

func AcquireByteBuffer() *ByteBuffer

AcquireByteBuffer returns an empty byte buffer from the pool.

Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.

func (*ByteBuffer) Bytes

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

Bytes returns b.B, i.e. all the bytes accumulated in the buffer.

The purpose of this function is bytes.Buffer compatibility.

func (*ByteBuffer) ChangeLen

func (b *ByteBuffer) ChangeLen(newLen int)

Reset makes ByteBuffer.B empty.

func (*ByteBuffer) Len

func (b *ByteBuffer) Len() int

Len returns the size of the byte buffer.

func (*ByteBuffer) ReadFrom

func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

The function appends all the data read from r to b.

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

Reset makes ByteBuffer.B empty.

func (*ByteBuffer) Set

func (b *ByteBuffer) Set(p []byte)

Set sets ByteBuffer.B to p.

func (*ByteBuffer) SetString

func (b *ByteBuffer) SetString(s string)

SetString sets ByteBuffer.B to s.

func (*ByteBuffer) String

func (b *ByteBuffer) String() string

String returns string representation of ByteBuffer.B.

func (*ByteBuffer) Write

func (b *ByteBuffer) Write(p []byte) (int, error)

Write implements io.Writer - it appends p to ByteBuffer.B

func (*ByteBuffer) WriteByte

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

WriteByte appends the byte c to the buffer.

The purpose of this function is bytes.Buffer compatibility.

The function always returns nil.

func (*ByteBuffer) WriteString

func (b *ByteBuffer) WriteString(s string) (int, error)

WriteString appends s to ByteBuffer.B.

func (*ByteBuffer) WriteTo

func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type ReaderWrap

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

func (*ReaderWrap) Read

func (rp *ReaderWrap) Read(p []byte) (int, error)

func (*ReaderWrap) Readed

func (rp *ReaderWrap) Readed() int

func (*ReaderWrap) Reset

func (rp *ReaderWrap) Reset(r io.Reader)

type WriterWrap

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

func (*WriterWrap) Reset

func (wp *WriterWrap) Reset(w io.Writer)

func (*WriterWrap) Write

func (wp *WriterWrap) Write(p []byte) (int, error)

func (*WriterWrap) Writed

func (wp *WriterWrap) Writed() int

Jump to

Keyboard shortcuts

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