utils

package
v0.0.0-...-2081a44 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NOW []byte = []byte("now")
View Source
var SP []byte = []byte(" ")
View Source
var ZeroULID = MyULID(string(zzz[:]))

ZeroULID is a zero ULID.

Functions

func All

func All(funs ...Func) (err eerrors.ErrorSlice)

All executes all the provided funcs and returns the errors.

func AnyErr

func AnyErr(errs ...error) (err error)

AnyErr returns the first error from the provided list.

func Atoi32

func Atoi32(s string) (int32, error)

Atoi32 returns the result of ParseInt(s, 10, 0) converted to type int32.

func Bytes2Time

func Bytes2Time(b []byte) (time.Time, int)

func Chain

func Chain(funs ...Func) (err error)

Chain executes the provided funcs until an error is returned.

func ChainWrites

func ChainWrites(dest io.Writer, buffers ...[]byte) (err error)

ChainWrites writes the provided buffers until an error is returned.

func FileExists

func FileExists(path string) bool

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func KafkaConsumerMetrics

func KafkaConsumerMetrics(mregistry metrics.Registry, basename string) (collectors []prometheus.Collector)

func KafkaProducerMetrics

func KafkaProducerMetrics(mregistry metrics.Registry, basename string) (collectors []prometheus.Collector)

func LsDir

func LsDir(path string) (res []string)

func MakeDecryptSplit

func MakeDecryptSplit(secret *memguard.LockedBuffer) bufio.SplitFunc

MakeDecryptSplit returns a split function that extracts and decrypts messages.

func MakeSignSplit

func MakeSignSplit(signpubkey *memguard.LockedBuffer) (signSplit bufio.SplitFunc)

MakeSignSplit returns a split function that checks for message signatures.

func NFields

func NFields(s []byte, n int) (fields [][]byte, advance int)

func NegotiateContentType

func NegotiateContentType(r *http.Request, serverOffers []string, defaultOffer string) string

func NewTLSConfig

func NewTLSConfig(address, caFile, caPath, certFile, keyFile string, insecure bool, confined bool) (*tls.Config, error)

NewTLSConfig builds and returns a TLS config from the provided parameters.

func NewUidString

func NewUidString() string

NewUidString generates a ULID for the current time and serializes it to a string.

func Parallel

func Parallel(funs ...Func) eerrors.ErrorSlice

Parallel executes the provided funcs in parallel and returns the errors

func PluginSplit

func PluginSplit(data []byte, atEOF bool) (advance int, token []byte, eoferr error)

PluginSplit is a split function used by plugins.

func PrintableUsASCII

func PrintableUsASCII(s string) bool

PrintableUsASCII returns true if the provided string is only composed by ASCII characters.

func Recover

func Recover(r interface{}) error

func RelpSplit

func RelpSplit(data []byte, atEOF bool) (advance int, token []byte, eoferr error)

RelpSplit is used to extract RELP lines from the incoming TCP stream

func SelectDecoder

func SelectDecoder(coding string) *encoding.Decoder

SelectDecoder returns a decoder from the provided coding string/

func Time2Bytes

func Time2Bytes(t time.Time, dst []byte) []byte

Types

type AcceptSpec

type AcceptSpec struct {
	Range   string
	Quality float64
	Params  []string
}

func ParseAccept

func ParseAccept(headers []string) (specs []AcceptSpec)

func (*AcceptSpec) Inferior

func (self *AcceptSpec) Inferior(other AcceptSpec) bool

func (*AcceptSpec) IsHalfWild

func (spec *AcceptSpec) IsHalfWild() bool

func (*AcceptSpec) IsWild

func (spec *AcceptSpec) IsWild() bool

func (*AcceptSpec) Match

func (spec *AcceptSpec) Match(offer string) bool

func (*AcceptSpec) SubType

func (spec *AcceptSpec) SubType() string

func (*AcceptSpec) Type

func (spec *AcceptSpec) Type() string

type CtxScanner

type CtxScanner struct {
	sync.Mutex

	sync.Once
	// contains filtered or unexported fields
}

func (*CtxScanner) Buffer

func (s *CtxScanner) Buffer(buf []byte, max int)

func (*CtxScanner) Bytes

func (s *CtxScanner) Bytes() []byte

func (*CtxScanner) Err

func (s *CtxScanner) Err() error

func (*CtxScanner) Scan

func (s *CtxScanner) Scan() bool

func (*CtxScanner) Split

func (s *CtxScanner) Split(f bufio.SplitFunc)

func (*CtxScanner) Text

func (s *CtxScanner) Text() string

type EncryptWriter

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

func NewEncryptWriter

func NewEncryptWriter(dest io.Writer, encryptkey *memguard.LockedBuffer) *EncryptWriter

func (*EncryptWriter) Write

func (s *EncryptWriter) Write(p []byte) (n int, err error)

func (*EncryptWriter) WriteMsgUnix

func (s *EncryptWriter) WriteMsgUnix(b []byte, oob []byte, addr *net.UnixAddr) (n int, oobn int, err error)

func (*EncryptWriter) WriteWithHeader

func (s *EncryptWriter) WriteWithHeader(header []byte, message []byte) (err error)

type Func

type Func func() error

type Generator

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

func NewGenerator

func NewGenerator() *Generator

func (*Generator) Uid

func (g *Generator) Uid() MyULID

type MyULID

type MyULID string

MyULID wraps ulid.ULID to allow protobuf marshaling.

func MustParseULID

func MustParseULID(uid string) MyULID

func NewUid

func NewUid() MyULID

NewUid returns a ULID for the current time.

func ParseMyULID

func ParseMyULID(uidStr string) (uid MyULID, err error)

ParseMyULID parse a string into a ULID.

func (MyULID) Compare

func (uid MyULID) Compare(other MyULID) int

Compare returns an integer comparing id and other lexicographically.

func (MyULID) Equal

func (uid MyULID) Equal(other MyULID) bool

Equal checks that two ULIDs are the same.

func (MyULID) Equals

func (uid MyULID) Equals(other gotomic.Thing) bool

Equals checks equality with a gotomic.Thing.

func (MyULID) HashCode

func (uid MyULID) HashCode() uint32

func (MyULID) Marshal

func (uid MyULID) Marshal() ([]byte, error)

Marshal marshals the ULID.

func (MyULID) MarshalJSON

func (uid MyULID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ULID to JSON.

func (MyULID) MarshalTo

func (uid MyULID) MarshalTo(dst []byte) (n int, err error)

MarshalTo marshals the ULID and writes it to dst.

func (*MyULID) Size

func (uid *MyULID) Size() int

Size returns the size of the ULID in bytes.

func (MyULID) String

func (uid MyULID) String() string

func (*MyULID) Unmarshal

func (uid *MyULID) Unmarshal(data []byte) error

Unmarshal unmarshals the data into a ULID.

func (*MyULID) UnmarshalJSON

func (uid *MyULID) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the data into a ULID using JSON.

type OFile

type OFile struct {
	Name string
	// contains filtered or unexported fields
}

func NewOFile

func NewOFile(f *os.File, name string, closeAt time.Time, bufferSize int, doGzip bool, gzipLevel int, logger log15.Logger) *OFile

func (*OFile) Acquire

func (o *OFile) Acquire()

func (*OFile) Expired

func (o *OFile) Expired() bool

func (*OFile) Flush

func (o *OFile) Flush() (err error)

func (*OFile) Postpone

func (o *OFile) Postpone(d time.Duration)

func (*OFile) Release

func (o *OFile) Release() bool

func (*OFile) Sync

func (o *OFile) Sync() (err error)

func (*OFile) Write

func (o *OFile) Write(p []byte) (int, error)

type RecoverScanner

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

func WithRecover

func WithRecover(scanner Scanner) *RecoverScanner

func (*RecoverScanner) Buffer

func (s *RecoverScanner) Buffer(buf []byte, max int)

func (*RecoverScanner) Bytes

func (s *RecoverScanner) Bytes() []byte

func (*RecoverScanner) Err

func (s *RecoverScanner) Err() error

func (*RecoverScanner) Scan

func (s *RecoverScanner) Scan() (ret bool)

func (*RecoverScanner) Split

func (s *RecoverScanner) Split(f bufio.SplitFunc)

func (*RecoverScanner) Text

func (s *RecoverScanner) Text() string

type RefCount

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

func NewRefCount

func NewRefCount() *RefCount

func (*RefCount) Dec

func (r *RefCount) Dec(uid MyULID) bool

func (*RefCount) GC

func (r *RefCount) GC() (ret []MyULID)

func (*RefCount) Inc

func (r *RefCount) Inc(uid MyULID)

func (*RefCount) New

func (r *RefCount) New(uid MyULID, init int32)

func (*RefCount) Remove

func (r *RefCount) Remove(uid MyULID)

type Scanner

type Scanner interface {
	Scan() bool
	Err() error
	Bytes() []byte
	Text() string
	Buffer([]byte, int)
	Split(bufio.SplitFunc)
}

func WithContext

func WithContext(ctx context.Context, scanner Scanner) Scanner

type Semaphore

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

func NewSemaphore

func NewSemaphore(total int32) *Semaphore

func (*Semaphore) Acquire

func (s *Semaphore) Acquire() error

func (*Semaphore) Dispose

func (s *Semaphore) Dispose()

func (*Semaphore) Release

func (s *Semaphore) Release()

type SigWriter

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

func NewSignatureWriter

func NewSignatureWriter(dest io.Writer, privsignkey *memguard.LockedBuffer) *SigWriter

func (*SigWriter) Write

func (s *SigWriter) Write(p []byte) (n int, err error)

func (*SigWriter) WriteWithHeader

func (s *SigWriter) WriteWithHeader(header []byte, message []byte) (err error)

type UIDString

type UIDString struct {
	UID MyULID
	S   string
}

Directories

Path Synopsis
Package civil implements types for civil time, a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.
Package civil implements types for civil time, a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
filetrie
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
inttrie
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
Package ctrie provides an implementation of the Ctrie data structure, which is a concurrent, lock-free hash trie.
Package logging is a generated protocol buffer package.
Package logging is a generated protocol buffer package.
tcp
udp

Jump to

Keyboard shortcuts

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