Documentation ¶
Overview ¶
Copyright 2017 Mailgun Technologies Inc
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Modifications Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This work is derived from github.com/golang/groupcache/lru
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func AdvanceSleepClock(clock Clock, d time.Duration)
- func BackOff(attempt int) time.Duration
- func GetEnv(envName, defaultValue string) string
- func IsZero(value interface{}) bool
- func IsZeroValue(value reflect.Value) bool
- func RandomAlpha(prefix string, length int) string
- func RandomDomainName() string
- func RandomItem(items ...string) string
- func RandomRunes(prefix string, length int, runes ...string) string
- func RandomString(prefix string, length int) string
- func SetDefault(dest interface{}, defaultValue ...interface{})
- func SetOverride(dest interface{}, values ...interface{})
- func ToFields(value interface{}) logrus.Fields
- type BackOffCounter
- type Broadcaster
- type Clock
- type ExpireCache
- func (c *ExpireCache) Add(key interface{}, value interface{})
- func (c *ExpireCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error
- func (c *ExpireCache) Get(key interface{}) (interface{}, bool)
- func (c *ExpireCache) GetStats() ExpireCacheStats
- func (c *ExpireCache) Keys() (keys []interface{})
- func (c *ExpireCache) Peek(key interface{}) (value interface{}, ok bool)
- func (c *ExpireCache) Size() int64
- func (c *ExpireCache) Update(key interface{}, value interface{}) error
- type ExpireCacheStats
- type FanOut
- type FrozenClock
- type Key
- type LRUCache
- func (c *LRUCache) Add(key Key, value interface{}) bool
- func (c *LRUCache) AddWithTTL(key Key, value interface{}, TTL time.Duration) bool
- func (c LRUCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error
- func (c *LRUCache) Get(key Key) (value interface{}, ok bool)
- func (c *LRUCache) Keys() (keys []interface{})
- func (c *LRUCache) Peek(key interface{}) (value interface{}, ok bool)
- func (c *LRUCache) Remove(key Key)
- func (c *LRUCache) Size() int
- func (c *LRUCache) Stats() LRUCacheStats
- type LRUCacheStats
- type PQItem
- type PriorityQueue
- type SleepClock
- type SystemClock
- type TTLMap
- func (m *TTLMap) Get(key string) (interface{}, bool)
- func (m *TTLMap) GetInt(key string) (int, bool, error)
- func (m *TTLMap) Increment(key string, value int, ttlSeconds int) (int, error)
- func (m *TTLMap) Len() int
- func (m *TTLMap) RemoveExpired(iterations int) int
- func (m *TTLMap) RemoveLastUsed(iterations int)
- func (m *TTLMap) Set(key string, value interface{}, ttlSeconds int) error
- type WaitGroup
Constants ¶
const AlphaRunes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const NumericRunes = "0123456789"
Variables ¶
This section is empty.
Functions ¶
func AdvanceSleepClock ¶
Helper method for sleep clock (See SleepClock.Advance())
func BackOff ¶
BackOff is a convenience function which returns a back off duration with a default 300 millisecond minimum and a 30 second maximum with a factor of 2 for each attempt.
func IsZero ¶
func IsZero(value interface{}) bool
Returns true if 'value' is zero (the default golang value)
var thingy string holster.IsZero(thingy) == true
func IsZeroValue ¶
Returns true if 'value' is zero (the default golang value)
var count int64 holster.IsZeroValue(reflect.ValueOf(count)) == true
func RandomAlpha ¶
Return a random string of alpha characters
func RandomDomainName ¶
func RandomDomainName() string
Return a random domain name in the form "randomAlpha.net"
func RandomItem ¶
Given a list of strings, return one of the strings randomly
func RandomRunes ¶
Return a random string made up of characters passed
func RandomString ¶
Return a random string of alpha and numeric characters
func SetDefault ¶
func SetDefault(dest interface{}, defaultValue ...interface{})
If 'dest' is empty or of zero value, assign the default value. This panics if the value is not a pointer or if value and default value are not of the same type.
var config struct { Verbose *bool Foo string Bar int } holster.SetDefault(&config.Foo, "default") holster.SetDefault(&config.Bar, 200)
Supply additional default values and SetDefault will choose the first default that is not of zero value
holster.SetDefault(&config.Foo, os.Getenv("FOO"), "default")
func SetOverride ¶
func SetOverride(dest interface{}, values ...interface{})
Assign the first value that is not empty or of zero value. This panics if the value is not a pointer or if value and default value are not of the same type.
var config struct { Verbose *bool Foo string Bar int } loadFromFile(&config) argFoo = flag.String("foo", "", "foo via cli arg") // Override the config file if 'foo' is provided via // the cli or defined in the environment. holster.SetOverride(&config.Foo, *argFoo, os.Env("FOO"))
Supply additional values and SetOverride() will choose the first value that is not of zero value. If all values are empty or zero the 'dest' will remain unchanged.
Types ¶
type BackOffCounter ¶
type BackOffCounter struct {
// contains filtered or unexported fields
}
func NewBackOff ¶
func NewBackOff(min, max time.Duration, factor float64) *BackOffCounter
func (*BackOffCounter) BackOff ¶
func (b *BackOffCounter) BackOff(attempt int) time.Duration
BackOff calculates the back depending on the attempts provided
func (*BackOffCounter) Next ¶
func (b *BackOffCounter) Next() time.Duration
Next returns the next back off duration based on the number of times Next() was called. Each call to next returns the next factor of back off. Call Reset() to reset the back off attempts to zero.
func (*BackOffCounter) Reset ¶
func (b *BackOffCounter) Reset()
Reset sets the back off attempt counter to zero
type Broadcaster ¶
func NewBroadcaster ¶
func NewBroadcaster() Broadcaster
type ExpireCache ¶
type ExpireCache struct {
// contains filtered or unexported fields
}
ExpireCache is a cache which expires entries only after 2 conditions are met 1. The Specified TTL has expired 2. The item has been processed with ExpireCache.Each()
This is an unbounded cache which guaranties each item in the cache has been processed before removal. This is different from a LRU cache, as the cache might decide an item needs to be removed (because we hit the cache limit) before the item has been processed.
Every time an item is touched by `Get()` or `Add()` the duration is updated which ensures items in frequent use stay in the cache
Processing can modify the item in the cache without updating the expiration time by using the `Update()` method
The cache can also return statistics which can be used to graph track the size of the cache
NOTE: Because this is an unbounded cache, the user MUST process the cache with `Each()` regularly! Else the cache items will never expire and the cache will eventually eat all the memory on the system
func NewExpireCache ¶
func NewExpireCache(ttl time.Duration) *ExpireCache
New creates a new ExpireCache.
func (*ExpireCache) Add ¶
func (c *ExpireCache) Add(key interface{}, value interface{})
Put the key, value and TTL in the cache
func (*ExpireCache) Each ¶
func (c *ExpireCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error
Processes each item in the cache in a thread safe way, such that the cache can be in use while processing items in the cache
func (*ExpireCache) Get ¶
func (c *ExpireCache) Get(key interface{}) (interface{}, bool)
Retrieves a key's value from the cache
func (*ExpireCache) GetStats ¶
func (c *ExpireCache) GetStats() ExpireCacheStats
Retrieve stats about the cache
func (*ExpireCache) Keys ¶
func (c *ExpireCache) Keys() (keys []interface{})
Get a list of keys at this point in time
func (*ExpireCache) Peek ¶
func (c *ExpireCache) Peek(key interface{}) (value interface{}, ok bool)
Get the value without updating the expiration
func (*ExpireCache) Size ¶
func (c *ExpireCache) Size() int64
Returns the number of items in the cache.
func (*ExpireCache) Update ¶
func (c *ExpireCache) Update(key interface{}, value interface{}) error
Update the value in the cache without updating the TTL
type ExpireCacheStats ¶
type FanOut ¶
type FanOut struct {
// contains filtered or unexported fields
}
FanOut spawns a new go-routine each time `Run()` is called until `size` is reached, subsequent calls to `Run()` will block until previously `Run()` routines have completed. Allowing the user to control how many routines will run simultaneously. `Wait()` then collects any errors from the routines once they have all completed.
type FrozenClock ¶
Manually controlled clock for use in tests Advance time by calling FrozenClock.Sleep()
func (*FrozenClock) Now ¶
func (t *FrozenClock) Now() time.Time
func (*FrozenClock) Sleep ¶
func (t *FrozenClock) Sleep(d time.Duration)
type Key ¶
type Key interface{}
A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type LRUCache ¶
type LRUCache struct { // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specifies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{}) // contains filtered or unexported fields }
Cache is an thread safe LRU cache that also supports optional TTL expiration You can use an non thread safe version of this
func NewLRUCache ¶
New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRUCache) AddWithTTL ¶
Adds a value to the cache with a TTL
func (LRUCache) Each ¶
func (c LRUCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error
Processes each item in the cache in a thread safe way, such that the cache can be in use while processing items in the cache. Processing the cache with `Each()` does not update the expiration or last used.
func (*LRUCache) Keys ¶
func (c *LRUCache) Keys() (keys []interface{})
Get a list of keys at this point in time
func (*LRUCache) Stats ¶
func (c *LRUCache) Stats() LRUCacheStats
Returns stats about the current state of the cache
type LRUCacheStats ¶
Holds stats collected about the cache
type PQItem ¶
type PQItem struct { Value interface{} Priority int // The priority of the item in the queue. // contains filtered or unexported fields }
An PQItem is something we manage in a priority queue.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
Implements a PriorityQueue
func NewPriorityQueue ¶
func NewPriorityQueue() *PriorityQueue
func (PriorityQueue) Len ¶
func (p PriorityQueue) Len() int
func (*PriorityQueue) Peek ¶
func (p *PriorityQueue) Peek() *PQItem
func (*PriorityQueue) Pop ¶
func (p *PriorityQueue) Pop() *PQItem
func (*PriorityQueue) Push ¶
func (p *PriorityQueue) Push(el *PQItem)
func (*PriorityQueue) Remove ¶
func (p *PriorityQueue) Remove(el *PQItem)
func (*PriorityQueue) Update ¶
func (p *PriorityQueue) Update(el *PQItem, priority int)
Modifies the priority and value of an Item in the queue.
type SleepClock ¶
type SleepClock struct {
// contains filtered or unexported fields
}
SleepClock returns a Clock that has good fakes for time.Sleep and time.After. Both functions will behave as if time is frozen until you call AdvanceTimeBy, at which point any calls to time.Sleep that should return do return and any ticks from time.After that should happen do happen.
func (*SleepClock) Advance ¶
func (t *SleepClock) Advance(d time.Duration)
Simulates advancing time by some time.Duration (Use for testing only)
func (*SleepClock) Now ¶
func (t *SleepClock) Now() time.Time
func (*SleepClock) Sleep ¶
func (t *SleepClock) Sleep(d time.Duration)
type SystemClock ¶
type SystemClock struct{}
system clock, time as reported by the operating system. Use this in production workloads.
func (*SystemClock) Now ¶
func (*SystemClock) Now() time.Time
func (*SystemClock) Sleep ¶
func (*SystemClock) Sleep(d time.Duration)
type TTLMap ¶
type TTLMap struct { // Optionally specifies a callback function to be // executed when an entry has expired OnExpire func(key string, i interface{}) // Optionally specify a time custom time object // used to determine if an item has expired Clock Clock // contains filtered or unexported fields }
func NewTTLMapWithClock ¶
func (*TTLMap) RemoveExpired ¶
func (*TTLMap) RemoveLastUsed ¶
type WaitGroup ¶
type WaitGroup struct {
// contains filtered or unexported fields
}
func (*WaitGroup) Loop ¶
Run a goroutine in a loop continuously, if the callBack returns false the loop is broken
func (*WaitGroup) Stop ¶
func (wg *WaitGroup) Stop()
closes the done channel passed into `Until()` calls and waits for the `Until()` callBack to return false
func (*WaitGroup) Until ¶
Run a goroutine in a loop continuously, if the callBack returns false the loop is broken. `Until()` differs from `Loop()` in that if the `Stop()` is called on the WaitGroup the `done` channel is closed. Implementations of the callBack function can listen for the close to indicate a stop was requested.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package clock provides the same functions as the system package time.
|
Package clock provides the same functions as the system package time. |
cmd
|
|
bunker
Bunkercmd is a command-line wrapper for bunker.
|
Bunkercmd is a command-line wrapper for bunker. |
Package errors provides simple error handling primitives.
|
Package errors provides simple error handling primitives. |
Provides tools for signing and authenticating HTTP requests between web services An keyed-hash message authentication code (HMAC) is used to provide integrity and authenticity of a message between web services.
|
Provides tools for signing and authenticating HTTP requests between web services An keyed-hash message authentication code (HMAC) is used to provide integrity and authenticity of a message between web services. |
rfc
|
|