Documentation ¶
Overview ¶
Package leverutil provides general utility functions that are not specific to Lever.
Index ¶
- Constants
- Variables
- func ExpBackoff(tryFun TryFun, startBackoff time.Duration, maxTriesDuration time.Duration) (result interface{}, err error)
- func GetRand() (tmpRand *rand.Rand)
- func PutRand(tmpRand *rand.Rand)
- func RandomHostName() string
- func RandomID() string
- func Tar(writer io.Writer, sourceDir string) error
- func Untar(reader io.Reader, targetDir string) error
- func UpdateLoggingSettings()
- type Cache
- type Logger
- func (logger *Logger) Debug(msg string)
- func (logger *Logger) Entry() *logrus.Entry
- func (logger *Logger) Error(msg string)
- func (logger *Logger) Fatal(msg string)
- func (logger *Logger) Info(msg string)
- func (logger *Logger) Panic(msg string)
- func (logger *Logger) Warning(msg string)
- func (logger *Logger) WithFields(args ...interface{}) (ret *Logger)
- type TryFun
- type UnboundedChannel
Constants ¶
const PackageName = "leverutil"
PackageName is the name of this package.
Variables ¶
var ( // ErrNotYetConstructed is returned when the cache element has not yet been // initialized. ErrNotYetConstructed = fmt.Errorf("Not yet constructed") // ErrWasDestructed is returned if the element has just been destructed. ErrWasDestructed = fmt.Errorf("Was destructed") )
var ( // ServiceFlag is the service name that will be attached to log entries. ServiceFlag = config.DeclareString("", "service", "") // InstanceIDFlag is the instance ID that will be attached to log entries. InstanceIDFlag = config.DeclareString("", "instanceID", RandomID()) // ContainerNameFlag is the name of the container this is running as (needs // to be set correctly from command line arg). This is used to determine // the containerID. ContainerNameFlag = config.DeclareString("", "containerName", "") )
var ( // LoggingFormatFlag is the format of log lines. LoggingFormatFlag = config.DeclareString( PackageName, "loggingFormat", "colortext") // LoggingLevelFlag is the minimum level to log. LoggingLevelFlag = config.DeclareString( PackageName, "loggingLevel", "info") // LogInstanceAndServiceFlag causes all loggers to also log the instance ID // and service name of the process. Useful if logs from multiple sources // are merged and need to be filtered afterwards. LogInstanceAndServiceFlag = config.DeclareBool( PackageName, "logInstanceAndService") )
Functions ¶
func ExpBackoff ¶
func ExpBackoff( tryFun TryFun, startBackoff time.Duration, maxTriesDuration time.Duration) (result interface{}, err error)
ExpBackoff retries tryFun with exponential backoff, until error is nil or finalErr is not nil, or the total time spent trying exceeds maxTriesDuration.
func RandomHostName ¶
func RandomHostName() string
RandomHostName returns a random name that can be used as part of a host name.
func UpdateLoggingSettings ¶
func UpdateLoggingSettings()
UpdateLoggingSettings initializes logging based on config params.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a data structure that keeps in-memory instances of objects for a specified amount of time after their last use.
func NewCache ¶
func NewCache( expiry time.Duration, constructor func(string) (interface{}, error), destructor func(interface{})) *Cache
NewCache creates a new Cache object.
func (*Cache) Get ¶
Get returns either a cached instance with provided key or a newly constructed one, if an instance is not found.
func (*Cache) GetExisting ¶
GetExisting returns a cached instance with provided key, if it exists.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a logger with some metadata associated.
func (*Logger) WithFields ¶
WithFields returns a new logger with provided metadata fields attached.
type UnboundedChannel ¶
type UnboundedChannel struct {
// contains filtered or unexported fields
}
UnboundedChannel is a channel with unlimited capacity.
func NewUnboundedChannel ¶
func NewUnboundedChannel() *UnboundedChannel
NewUnboundedChannel returns a new UnboundedChannel.
func (*UnboundedChannel) Get ¶
func (uc *UnboundedChannel) Get() <-chan interface{}
Get returns the channel that can be listened to for the next available element. Call Load right after receiving anything from the channel in order to load the next element for receiving.
func (*UnboundedChannel) Load ¶
func (uc *UnboundedChannel) Load()
Load loads the next item to be received via Get.
func (*UnboundedChannel) Put ¶
func (uc *UnboundedChannel) Put(element interface{})
Put appends the element to the channel.