providerutil

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package providerutil contains small helpers shared by quota-style providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractObjects

func ExtractObjects(v any, match func(map[string]any) bool) []map[string]any

ExtractObjects walks arbitrary JSON and returns objects accepted by match.

func FirstFloat

func FirstFloat(m map[string]any, keys ...string) (float64, bool)

FirstFloat returns the first numeric value for keys.

func FirstString

func FirstString(m map[string]any, keys ...string) string

FirstString returns the first non-empty string-like value for keys.

func FirstTime

func FirstTime(m map[string]any, keys ...string) (*time.Time, bool)

FirstTime returns the first date-like value for keys.

func FloatValue

func FloatValue(v any) (float64, bool)

FloatValue converts a JSON scalar to float64.

func MapValue

func MapValue(v any) (map[string]any, bool)

MapValue returns v as a JSON object when possible.

func MissingAuthSnapshot

func MissingAuthSnapshot(providerID, providerName, message string) providers.Snapshot

MissingAuthSnapshot returns a configured-but-missing-credentials snapshot.

func NestedMap

func NestedMap(root map[string]any, keys ...string) (map[string]any, bool)

NestedMap follows keys through nested JSON objects.

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 ResetSeconds

func ResetSeconds(resetAt time.Time) *float64

ResetSeconds returns seconds from now until resetAt, clamped to zero.

func RootMap

func RootMap(body []byte) (map[string]any, error)

RootMap decodes arbitrary JSON into a root object. Top-level arrays are wrapped as {"quotas": array} to keep provider parsers uniform.

func RootMapFromAny

func RootMapFromAny(raw any) (map[string]any, error)

RootMapFromAny normalizes a decoded JSON value into a root object.

func StringValue

func StringValue(v any) string

StringValue converts a JSON scalar to a trimmed string.

func TimeValue

func TimeValue(v any) (time.Time, bool)

TimeValue converts RFC3339 strings or Unix timestamps into time.Time.

Types

type CommandResult

type CommandResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

CommandResult is the captured output from a completed CLI command.

func RunCommand

func RunCommand(ctx context.Context, name string, args ...string) (CommandResult, error)

RunCommand runs a CLI command with stdout and stderr captured separately.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL