Documentation
¶
Overview ¶
Package providerutil contains small helpers shared by quota-style providers.
Index ¶
- func ExtractObjects(v any, match func(map[string]any) bool) []map[string]any
- func FirstFloat(m map[string]any, keys ...string) (float64, bool)
- func FirstString(m map[string]any, keys ...string) string
- func FirstTime(m map[string]any, keys ...string) (*time.Time, bool)
- func FloatValue(v any) (float64, bool)
- func MapValue(v any) (map[string]any, bool)
- func MissingAuthSnapshot(providerID, providerName, message string) providers.Snapshot
- func NestedMap(root map[string]any, keys ...string) (map[string]any, bool)
- func NowString() string
- func PercentRemainingMetric(id, label, name string, usedPct float64, resetAt *time.Time, caption string, ...) providers.MetricValue
- func RawCounts(m providers.MetricValue, remaining, total int) providers.MetricValue
- func ReplaceFileAtomic(tmpPath, path string) error
- func ResetSeconds(resetAt time.Time) *float64
- func ResetTimeWhenUsed(usedPct float64, resetAt *time.Time) *time.Time
- func RootMap(body []byte) (map[string]any, error)
- func RootMapFromAny(raw any) (map[string]any, error)
- func StringValue(v any) string
- func TimeValue(v any) (time.Time, bool)
- func WriteAtomic(path string, data []byte) error
- func WriteJSONAtomic(path string, data any) error
- type CommandResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractObjects ¶
ExtractObjects walks arbitrary JSON and returns objects accepted by match.
func FirstFloat ¶
FirstFloat returns the first numeric value for keys.
func FirstString ¶
FirstString returns the first non-empty string-like value for keys.
func FloatValue ¶
FloatValue converts a JSON scalar to float64.
func MissingAuthSnapshot ¶
MissingAuthSnapshot returns a configured-but-missing-credentials snapshot.
func NowString ¶
func NowString() string
NowString returns the timestamp format used by provider metrics.
func PercentRemainingMetric ¶
func PercentRemainingMetric(id, label, name string, usedPct float64, resetAt *time.Time, caption string, now string) providers.MetricValue
PercentRemainingMetric builds a standard remaining-percent metric from a used percentage.
func RawCounts ¶
func RawCounts(m providers.MetricValue, remaining, total int) providers.MetricValue
RawCounts attaches remaining and total counts to a metric.
func ReplaceFileAtomic ¶ added in v0.7.3
ReplaceFileAtomic replaces path with tmpPath on platforms where os.Rename is atomic.
func ResetSeconds ¶
ResetSeconds returns seconds from now until resetAt, clamped to zero.
func ResetTimeWhenUsed ¶ added in v0.8.0
ResetTimeWhenUsed returns resetAt only when usedPct indicates real usage. Reset countdowns are misleading on otherwise-idle quotas — "100% remaining for 23h 47m" tells the user nothing actionable, since the reset only matters once usage starts. Providers whose reset window has this property should pass their resetAt through this helper before handing it to PercentRemainingMetric.
Threshold is 0.5% to absorb float-rounding artifacts when the API reports e.g. 99.9999% remaining for an effectively-idle window.
func RootMap ¶
RootMap decodes arbitrary JSON into a root object. Top-level arrays are wrapped as {"quotas": array} to keep provider parsers uniform.
func RootMapFromAny ¶
RootMapFromAny normalizes a decoded JSON value into a root object.
func StringValue ¶
StringValue converts a JSON scalar to a trimmed string.
func WriteAtomic ¶ added in v0.7.3
WriteAtomic writes data to path using atomic replace semantics.
func WriteJSONAtomic ¶ added in v0.7.3
WriteJSONAtomic writes data to path using atomic replace semantics.
Types ¶
type CommandResult ¶
CommandResult is the captured output from a completed CLI command.
func RunCommand ¶
RunCommand runs a CLI command with stdout and stderr captured separately.