toolkit

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: BSD-2-Clause Imports: 13 Imported by: 19

README

toolkit

Started with several utilities to support http://github.com/quintans/goSQL but now also has several tools that I use in my pet projects.

The most relevant are:

  • Web
    • Filters
    • JSON-RPC Server
    • Session Management
    • Only Files File System
    • Long Polling (xhr)
  • Log
    • Logging with Asynchronous Writers and Hierarchy Log Levels
    • ConsoleAppender
    • RollingFileAppender
  • Cache
    • LRUCache
    • ExpirationCache
  • Collection
    • HashMap
    • LinkedHashMap
    • HashSet
    • LinkedHashSet
    • FIFO
  • QuickSort

Dependencies

https://code.google.com/p/go-uuid/

Credits

Documentation

Index

Constants

View Source
const HASH_SEED = 23

*

  • An initial value for a <code>hashCode</code>, to which is added contributions
  • from fields. Using a non-zero value decreases collisons of <code>hashCode</code>
  • values.
View Source
const UUID_SIZE = 16

Variables

This section is empty.

Functions

func CapFirst

func CapFirst(str string) string

CapFirst returns the input string with the first letter in Upper case

func Hash

func Hash(aSeed int, aObject interface{}) int

func HashBase

func HashBase(aSeed int, a Base) int

func HashBool

func HashBool(aSeed int, aBoolean bool) int

*

  • booleans.

func HashBytes

func HashBytes(aSeed int, aBytes []byte) int

func HashDouble

func HashDouble(aSeed int, aDouble float64) int

func HashFloat

func HashFloat(aSeed int, aFloat float32) int

func HashInt

func HashInt(aSeed int, aInt int) int

func HashInteger

func HashInteger(aSeed int, aInt int32) int

func HashLong

func HashLong(aSeed int, aLong int64) int

func HashShort

func HashShort(aSeed int, aInt int16) int

func HashString

func HashString(aSeed int, aString string) int

func HashTiny

func HashTiny(aSeed int, aInt int8) int

func HashType

func HashType(aSeed int, aType interface{}) int

func HashUnit

func HashUnit(aSeed int, aInt byte) int

func LoadConfiguration

func LoadConfiguration(config interface{}, file string, mandatory bool) error

LoadConfiguration configuration from a json file config is a pointer to a configuration variable file is the json file location

func Match

func Match(o1, o2 interface{}) bool

func Milliseconds

func Milliseconds() int64

func Set

func Set(instance interface{}, value interface{})

func SliceContains

func SliceContains(list interface{}, elem interface{}) bool

func ToString

func ToString(v interface{}) string

func UncapFirst

func UncapFirst(str string) string

UncapFirst returns the input string with the first letter in lower case

Types

type Base

type Base interface {
	Hasher
	Clonable
	fmt.Stringer
}

type Clonable

type Clonable interface {
	Clone() interface{}
}

type Codec

type Codec interface {
	Encode(interface{}) ([]byte, error)
	Decode([]byte, interface{}) error
}

type Debouncer

type Debouncer struct {
	OnExit func()
	// contains filtered or unexported fields
}

Debouncer struct to support debouncing

func NewDebounce

func NewDebounce(interval time.Duration, action func(arg interface{})) *Debouncer

NewDebounce creates a new Debouncer

func (*Debouncer) Delay

func (debounce *Debouncer) Delay(item interface{})

Delay delays the execution of action declared when we created the debouncer

func (*Debouncer) Kill

func (debounce *Debouncer) Kill()

Kill terminates the debouncer

type Equaler

type Equaler interface {
	Equals(other interface{}) bool
}

type Fail

type Fail struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (*Fail) Error

func (this *Fail) Error() string

func (*Fail) GetCode

func (this *Fail) GetCode() string

func (*Fail) GetMessage

func (this *Fail) GetMessage() string

type Fault

type Fault interface {
	error
	GetCode() string
	GetMessage() string
}

type GobCodec

type GobCodec struct {
}

func (GobCodec) Decode

func (this GobCodec) Decode(payload []byte, p interface{}) error

func (GobCodec) Encode

func (this GobCodec) Encode(data interface{}) ([]byte, error)

type Hasher

type Hasher interface {
	Equaler
	HashCode() int
}

type Joiner

type Joiner struct {
	*StrBuffer
	// contains filtered or unexported fields
}

func NewJoiner

func NewJoiner(separator string) *Joiner

func (*Joiner) Add

func (this *Joiner) Add(a ...interface{}) *Joiner

func (*Joiner) AddAsOne

func (this *Joiner) AddAsOne(a ...interface{}) *Joiner

func (*Joiner) Append

func (this *Joiner) Append(a ...interface{}) *Joiner

type JsonCodec

type JsonCodec struct {
}

func (JsonCodec) Decode

func (this JsonCodec) Decode(payload []byte, p interface{}) error

func (JsonCodec) Encode

func (this JsonCodec) Encode(data interface{}) ([]byte, error)

type LazyString

type LazyString func() string

LazyString enable us to use a function in fmt.(S)Printf eg: fmt.Printf(

"Hello %s",
LazyString(func() string {
return "world!"
}),

)

func (LazyString) String

func (ls LazyString) String() string

type Rate

type Rate interface {
	TakeN(int64) time.Duration
}

type RateLimiter

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RateLimiter is a simple implementation of the Leaky Bucket algorithm.

Simple use: var rl = NewRateLimiter(2) // per second

for i := 0; i < 10; i++ {
  var wait = rl.Take()
  fmt.Println(time.Now(), wait)
}

func NewRateLimiter

func NewRateLimiter(rate int64) *RateLimiter

NewRateLimiter creates an instance of RateLimiter rate sets the number of takes that can occur per second

func (*RateLimiter) Take

func (rl *RateLimiter) Take() time.Duration

Take is the same as TakeN(1)

func (*RateLimiter) TakeN

func (rl *RateLimiter) TakeN(amount int64) time.Duration

TakeN enforces the rate limit. amount is the value over which we apply the rate and it returns the time waiting before returning. If previous calls to TakeN() had the consequence of breaking the rate limit, then the current call will wait until the rate is again below the rate limit. If we want to limit a stream of data to 4Kb/s we do the following: var rl = NewRateLimiter(4000) // per second func submit(data []byte)

  rl.Take(len(data))
  service.send(data);
}

type StrBuffer

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

func NewStrBuffer

func NewStrBuffer(str ...interface{}) *StrBuffer

func (*StrBuffer) Add

func (this *StrBuffer) Add(a ...interface{}) *StrBuffer

func (*StrBuffer) Addf

func (this *StrBuffer) Addf(template string, a ...interface{}) *StrBuffer

func (*StrBuffer) Clear

func (this *StrBuffer) Clear()

func (*StrBuffer) Clone

func (this *StrBuffer) Clone() interface{}

func (*StrBuffer) Equals

func (this *StrBuffer) Equals(e interface{}) bool

func (*StrBuffer) HashCode

func (this *StrBuffer) HashCode() int

func (*StrBuffer) IsEmpty

func (this *StrBuffer) IsEmpty() bool

func (*StrBuffer) Size

func (this *StrBuffer) Size() int

func (*StrBuffer) String

func (this *StrBuffer) String() string

type Ticker

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

func NewDelayedTicker

func NewDelayedTicker(delay time.Duration, duration time.Duration, hnd func(time.Time)) *Ticker

func NewTicker

func NewTicker(duration time.Duration, hnd func(time.Time)) *Ticker

func (*Ticker) Stop

func (tck *Ticker) Stop()

type UUID

type UUID [UUID_SIZE]byte

func NewUUID

func NewUUID() UUID

func ToUUID

func ToUUID(b []byte) (UUID, error)

func (UUID) Bytes

func (a UUID) Bytes() []byte

func (UUID) IsZero

func (a UUID) IsZero() bool

func (UUID) String

func (a UUID) String() string

Directories

Path Synopsis
web
app

Jump to

Keyboard shortcuts

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