billing

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package billing queries a provider's wallet balance for the status line. The only documented shape today is DeepSeek's GET /user/balance, so Fetch speaks that schema. Balance is strictly optional: a provider with no balance_url is never queried — callers pass "" and get (nil, nil) back, and surfaces simply omit the readout. Kept tiny and dependency-free (net/http + encoding/json) so every frontend can share one fetch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Available bool   // the provider reports the account can still serve API calls
	Infos     []Info // one entry per currency the provider returns
}

Balance is a wallet balance normalized for display.

func Fetch

func Fetch(ctx context.Context, url, apiKey string) (*Balance, error)

Fetch queries url (a DeepSeek-style balance endpoint) with a Bearer apiKey and returns the normalized balance. An empty url yields (nil, nil) — "not configured", not an error — so callers can treat both the same and just omit the readout.

func (*Balance) Display

func (b *Balance) Display() string

Display renders the primary balance compactly, e.g. "¥110.00". It prefers CNY, then the first currency reported. "" when there's nothing to show.

type Info

type Info struct {
	Currency        string // "CNY" | "USD"
	TotalBalance    string // total available (granted + topped-up)
	GrantedBalance  string // unexpired promotional credit
	ToppedUpBalance string // paid-in credit
}

Info is one currency's balance (DeepSeek returns one per currency).

Jump to

Keyboard shortcuts

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