Documentation
¶
Overview ¶
Package percent provides options for percent field rendering in clog.
Index ¶
- func Apply(p *Percent, opts []Option)
- func EffectiveMaximum(p Percent) float64
- func FormatFunc() func(float64) string
- func Maximum() float64
- func Precision() int
- func Restore(s Snapshot)
- func ReverseGradient() bool
- func SetFormatFunc(fn func(float64) string)
- func SetMaximum(m float64)
- func SetPrecision(n int)
- func SetReverseGradient(rev bool)
- type Option
- type Percent
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EffectiveMaximum ¶ added in v0.7.0
EffectiveMaximum returns the per-field maximum if set, otherwise the global maximum.
func FormatFunc ¶
FormatFunc returns the current custom format function, or nil if using default.
func Maximum ¶ added in v0.7.0
func Maximum() float64
Maximum returns the current global percent maximum (default 1.0).
func Restore ¶
func Restore(s Snapshot)
Restore resets the percent configuration to a previously saved Snapshot.
func ReverseGradient ¶
func ReverseGradient() bool
ReverseGradient reports whether the gradient is inverted.
func SetFormatFunc ¶
SetFormatFunc configures a custom format function for percent fields. When set to nil (the default), the built-in format is used.
func SetMaximum ¶ added in v0.7.0
func SetMaximum(m float64)
SetMaximum sets the percent maximum. The default is 1.0, meaning percent values are passed as fractions (e.g. 0.75 → "75%"). Set to 100 for 0–100 input (e.g. 75 → "75%").
func SetPrecision ¶
func SetPrecision(n int)
SetPrecision sets the number of decimal places for percent display. For example, 0 = "75%", 1 = "75.0%". Defaults to 0.
func SetReverseGradient ¶
func SetReverseGradient(rev bool)
SetReverseGradient reverses the gradient direction for percent fields. By default the gradient runs red (0%) → green (100%) - suitable for metrics where higher is better. Set reverse=true to flip it to green (0%) → red (100%) - suitable for metrics like CPU or disk usage where lower is better.
Types ¶
type Option ¶
type Option func(*Percent)
Option configures how a percent field is rendered.
func WithMaximum ¶ added in v0.7.0
WithMaximum returns an Option that overrides the global percent maximum for this field. For example, use WithMaximum(100) when passing values in the 0–100 range instead of the default 0–1 range.
func WithReverseGradient ¶
func WithReverseGradient() Option
WithReverseGradient returns an Option that flips the gradient direction for this field relative to the logger default. If the logger is using the normal gradient (red=0%, green=100%), the field renders inverted (green=0%, red=100%), and vice versa.