pricing

package
v0.0.0-...-611bec0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 20 Imported by: 10

Documentation

Index

Constants

View Source
const (
	ScopeProject     = "project"
	ScopeShared      = "shared"
	ScopeEnvironment = "environment"
	ScopeApp         = "app"
)
View Source
const AllowanceAssumed = "" /* 191-byte string literal not displayed */

Variables

View Source
var DefaultClient = Client{
	HTTP:     tracing.NewClient(0),
	Attempts: 6,
	Base:     500 * time.Millisecond,
	Ceiling:  30 * time.Second,
}
View Source
var MonthlyHours = decimal.NewFromInt(730)

Functions

func Estimate

func Estimate(card *Card, table Table, req *costv1.PriceRequest) (*costv1.Estimate, error)

func Fetch

func Fetch(ctx context.Context, req *http.Request) ([]byte, error)

func Priced

func Priced(card *Card, table Table, edges ...EdgeRates) (*Card, Table, error)

func ProfileName

func ProfileName(profile costv1.Profile) string

func Profiles

func Profiles() []costv1.Profile

func Struct

func Struct(values map[string]any) (*structpb.Struct, error)

Types

type Allowance

type Allowance string
const (
	AllowanceAccount  Allowance = "account"
	AllowanceResource Allowance = "resource"
)

type Band

type Band struct{ Light, Moderate, Heavy float64 }

type Card

type Card struct {
	Version  string `json:"version"`
	Currency string `json:"currency"`
	Rates    []Rate `json:"rates"`
	// contains filtered or unexported fields
}

func Load

func Load(raw []byte) (*Card, error)

func Merge

func Merge(primary *Card, others ...*Card) *Card

func (*Card) Lookup

func (c *Card) Lookup(id, region string) (rate Rate, found, fellBack bool)

type Client

type Client struct {
	HTTP     *http.Client
	Attempts int
	Base     time.Duration
	Ceiling  time.Duration
	Sleep    func(context.Context, time.Duration) error
}

func (Client) Fetch

func (c Client) Fetch(ctx context.Context, req *http.Request) ([]byte, error)

type Component

type Component struct {
	Name       string
	Unit       string
	Rate       string
	Quantity   decimal.Decimal
	UsageBased bool
	Assumption string
	Needs      []string
}

type EdgeApp

type EdgeApp struct {
	Name      string
	Hostnames []string
}

type EdgeRates

type EdgeRates struct {
	Card  func() (*Card, error)
	Table Table
}

type EdgeScopes

type EdgeScopes struct {
	Shared      string
	Environment string
}

type EdgeShape

type EdgeShape struct {
	Vendor      string
	Region      string
	BillsEgress bool
	Shared      []Shaped
	Environment []Shaped
	Apps        map[string][]Shaped
}

type EdgeSite

type EdgeSite struct {
	Slug   string
	Tier   environment.Tier
	Region string
	Apps   []EdgeApp
}

type Formula

type Formula func(*Subject)

type Rate

type Rate struct {
	ID        string            `json:"id"`
	Region    string            `json:"region,omitempty"`
	Unit      string            `json:"unit"`
	Steps     []Step            `json:"steps"`
	Allowance Allowance         `json:"allowance,omitempty"`
	Note      string            `json:"note,omitempty"`
	Source    string            `json:"source"`
	Verified  string            `json:"verified"`
	Query     map[string]string `json:"query,omitempty"`
}

func (Rate) Between

func (r Rate) Between(from, to decimal.Decimal) (cost, marginal decimal.Decimal)

func (Rate) Cost

func (r Rate) Cost(quantity decimal.Decimal) (cost, marginal decimal.Decimal)

type Shaped

type Shaped struct {
	Name       string
	Type       string
	Properties map[string]any
}

type Step

type Step struct {
	Start decimal.Decimal `json:"start"`
	Price decimal.Decimal `json:"price"`
}

type Subject

type Subject struct {
	Resource *costv1.Resource
	Region   string
	// contains filtered or unexported fields
}

func (*Subject) Add

func (s *Subject) Add(c Component)

func (*Subject) Bool

func (s *Subject) Bool(path string) bool

func (*Subject) Free

func (s *Subject) Free()

func (*Subject) Has

func (s *Subject) Has(path string) bool

func (*Subject) List

func (s *Subject) List(path string) []any

func (*Subject) Number

func (s *Subject) Number(path string) decimal.Decimal

func (*Subject) String

func (s *Subject) String(path string) string

func (*Subject) Unknown

func (s *Subject) Unknown(path string) bool

func (*Subject) Usage

func (s *Subject) Usage(key string, band Band) decimal.Decimal

type Table

type Table map[string]Formula

func Tables

func Tables(tables ...Table) Table

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

func (*Tree) Add

func (t *Tree) Add(scope, vendor, typ, name, region string, properties map[string]any, unknown ...string) *costv1.Resource

func (*Tree) AddEdge

func (t *Tree) AddEdge(scopes EdgeScopes, shape EdgeShape)

func (*Tree) AddShaped

func (t *Tree) AddShaped(scope, vendor, region string, shaped []Shaped)

func (*Tree) Scope

func (t *Tree) Scope(parent, kind, name string) string

func (*Tree) Set

func (t *Tree) Set(source string) (*costv1.ResourceSet, error)

type UsageError

type UsageError struct {
	Resource string
	Key      string
	Reason   string
}

func (*UsageError) Error

func (e *UsageError) Error() string

Jump to

Keyboard shortcuts

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