Documentation ¶
Index ¶
- Constants
- func ErrorCallerStackHandler(maxLvl log15.Lvl, handler log15.Handler) log15.Handler
- func ErrorWithCategory(category error, cause error) error
- func FloatToRational(floatVal float64) *big.Rat
- func HasErrorCategory(err error, category error) bool
- func NopOpenedCallback(*os.File, bool) error
- func ParseRational(str string) (*big.Rat, error)
- func RationalDiv(num, denom *big.Rat) *big.Rat
- func RationalToFloat(val *big.Rat) float64
- func RotatingLog(file string, level string) (log15.Logger, error)
- func StderrLog() log15.Logger
- func UnwrapCauseFromErrorCategory(err error, category error) error
- type Byte
- type Duration
- type LRUCache
- type Metrics
- type NoOpMetrics
- type OpenedCallback
- type RotatingFile
- type SizedEntry
- type SizedEntryFactory
- type SizedEntryRef
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ErrorCallerStackHandler ¶
ErrorCallerStackHandler creates a handler that drops all logs that are less important than maxLvl, and also adds a stack trace to all events that are errors / critical, as well as the error values that have a stack trace.
func ErrorWithCategory ¶
ErrorWithCategory is similar to errors.Wrap, but instead of creating a new error as the wrapping message, a sentinel error is provided as a category. This category can then be inspected with HasErrorCategory.
func FloatToRational ¶
FloatToRational returns a rational that's within 1e-6 of the floating-point value.
func HasErrorCategory ¶
HasErrorCategory returns whether the provided error belongs to the provided category.
func NopOpenedCallback ¶
NopOpenedCallback is an OpenedCallback that does nothing.
func ParseRational ¶
ParseRational returns a rational that's within 1e-6 of the floating-point value that has been serialized as a string.
func RationalDiv ¶
RationalDiv implements division between two rationals.
func RationalToFloat ¶
RationalToFloat returns the closest float value to the given big.Rat.
func RotatingLog ¶
RotatingLog opens a log15.Logger, and if it will be pointed to a real file, it installs a SIGHUP handler that will atomically reopen the file and redirect all future logging operations.
func StderrLog ¶
StderrLog creates a log15.Logger that outputs to stderr and prints the stack for the log call and the error stack trace if available.
func UnwrapCauseFromErrorCategory ¶
UnwrapCauseFromErrorCategory finds an error with the specified category in the chain and returns its Cause(). Returns nil if no such error was found.
Types ¶
type Byte ¶
type Byte int64
A Byte is a unit of digital information.
func (Byte) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The result is an integer number of bytes.
func (*Byte) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The result can be an integer number of bytes, or a quoted string that MarshalJSON() can understand.
type Duration ¶
Duration is identical to time.Duration, except it can implements the json.Marshaler interface with time.Duration.String() and time.Duration.ParseDuration().
func MaxDuration ¶
MaxDuration returns the larger of x or y.
func MinDuration ¶
MinDuration returns the smaller of x or y.
func (Duration) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The duration is a quoted string in RFC 3339 format, with sub-second precision added if present.
func (Duration) Milliseconds ¶
Milliseconds returns the duration as a floating point number of milliseconds.
func (Duration) String ¶
String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The duration is expected to be a quoted string that time.ParseDuration() can understand.
type LRUCache ¶
LRUCache handles a pool of sized resources. It has a fixed maximum size with a least-recently used eviction policy.
func NewLRUCache ¶
NewLRUCache returns an empty LRUCache with the provided size limit.
func (*LRUCache) EntryCount ¶
EntryCount is the number of elements in the LRUCache.
func (*LRUCache) EvictableSize ¶
EvictableSize is the size in bytes of all elements that are being considered for eviction. This is, not currently being used.
func (*LRUCache) Get ¶
func (c *LRUCache) Get( key string, factory SizedEntryFactory, ) (*SizedEntryRef, error)
Get atomically gets a previously-created entry if it was found in the cache, or a newly-created one otherwise. It is the caller's responsibility to call Put() with the returned SizedEntryRef method once it's no longer needed so that the underlying resource can be evicted from the cache, if needed.
func (*LRUCache) OvercommittedSize ¶
OvercommittedSize is the size in bytes that have been allocated above the LRUCache's size limit. This number can be non-zero when all the elements in the cache are currently being used and cannot yet be evicted.
func (*LRUCache) Put ¶
func (c *LRUCache) Put(r *SizedEntryRef)
Put marks a SizedEntryRef as no longer being referred to, so that it can be considered for eviction.
type Metrics ¶
type Metrics interface { // GaugeAdd increments a gauge. A gauge is a metric that represents a single // numerical value that can arbitrarily go up and down. GaugeAdd(name string, value float64) // CounterAdd increments a counter. A counter is a metric that represents a // single numerical value that only ever goes up. CounterAdd(name string, value float64) // SummaryObserve adds an observation to a summary. A summary is an aggregate // metric that supports querying percentiles. SummaryObserve(name string, value float64) }
Metrics is an interface that supports updating different kinds of metrics. All its functions are thread-safe.
type NoOpMetrics ¶
type NoOpMetrics struct { }
NoOpMetrics is an implementation of Metrics that does nothing.
func (*NoOpMetrics) CounterAdd ¶
func (n *NoOpMetrics) CounterAdd(name string, value float64)
CounterAdd adds the specified value to a counter of the specified name. Value should be non-negative.
func (*NoOpMetrics) GaugeAdd ¶
func (n *NoOpMetrics) GaugeAdd(name string, value float64)
GaugeAdd adds the specified value to a gauge of the specified name.
func (*NoOpMetrics) SummaryObserve ¶
func (n *NoOpMetrics) SummaryObserve(name string, value float64)
SummaryObserve adds the specified value to a summary of the specified name.
type OpenedCallback ¶
OpenedCallback allows the caller to specify an action to be performed when the file is opened and before it is available for writing.
type RotatingFile ¶
type RotatingFile struct {
// contains filtered or unexported fields
}
A RotatingFile is an io.WriteCloser that supports reopening through SIGHUP. It opens the underlying file in append-only mode. All operations are thread-safe.
func NewRotatingFile ¶
func NewRotatingFile(path string, mode os.FileMode, callback OpenedCallback) (*RotatingFile, error)
NewRotatingFile opens path for writing in append-only mode and listens for SIGHUP so that it can reopen the file automatically.
func (*RotatingFile) Close ¶
func (r *RotatingFile) Close() error
Close closes the underlying file and stops listening for SIGHUP.
func (*RotatingFile) Rotate ¶
func (r *RotatingFile) Rotate() error
Rotate reopens the file and closes the previous one.
func (*RotatingFile) Write ¶
func (r *RotatingFile) Write(b []byte) (int, error)
Write writes the bytes into the underlying file.
func (*RotatingFile) WriteString ¶
func (r *RotatingFile) WriteString(s string) (int, error)
WriteString is like Write, but writes the contents of string s rather than a slice of bytes.
type SizedEntry ¶
type SizedEntry interface { // Release will be called upon the entry being evicted from the cache. Release() // Size returns the number of bytes consumed by the entry. Size() Byte }
A SizedEntry is an entry within the LRUCache that knows its own size.
type SizedEntryFactory ¶
type SizedEntryFactory func(key string) (SizedEntry, error)
A SizedEntryFactory is a factory that can create a SizedEntry given its key name.
type SizedEntryRef ¶
type SizedEntryRef struct { Value SizedEntry // contains filtered or unexported fields }
A SizedEntryRef is a wrapper around a SizedEntry.