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 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 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.