meter

package
v1.42.3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func QueryEvents

func QueryEvents(db *datastore.Datastore) datastore.Query

Types

type AggregationType

type AggregationType string

AggregationType controls how meter events are aggregated.

const (
	AggSum   AggregationType = "sum"
	AggCount AggregationType = "count"
	AggLast  AggregationType = "last"
)

type Meter

type Meter struct {
	mixin.Model[Meter]

	Name            string          `json:"name"`
	EventName       string          `json:"eventName"`
	AggregationType AggregationType `json:"aggregationType"`
	Currency        currency.Type   `json:"currency"`

	// JSON-encoded list of dimension names, e.g. ["model","region"]
	Dimensions  []string `json:"dimensions,omitempty" datastore:"-"`
	Dimensions_ string   `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

func New

func New(db *datastore.Datastore) *Meter

func (*Meter) Defaults

func (m *Meter) Defaults()

func (*Meter) Load

func (m *Meter) Load(ps []datastore.Property) (err error)

func (*Meter) Save

func (m *Meter) Save() (ps []datastore.Property, err error)

func (*Meter) Validator

func (m *Meter) Validator() *val.Validator

type MeterEvent

type MeterEvent struct {
	mixin.Model[MeterEvent]

	MeterId   string    `json:"meterId"`
	UserId    string    `json:"userId"`
	Value     int64     `json:"value"`
	Timestamp time.Time `json:"timestamp"`

	// Idempotency key for deduplication
	Idempotency string `json:"idempotency,omitempty"`

	// JSON-encoded dimension values, e.g. {"model":"gpt-4","region":"us"}
	Dimensions  Map    `json:"dimensions,omitempty" datastore:"-"`
	Dimensions_ string `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

func NewEvent

func NewEvent(db *datastore.Datastore) *MeterEvent

func (*MeterEvent) Defaults

func (e *MeterEvent) Defaults()

func (*MeterEvent) Load

func (e *MeterEvent) Load(ps []datastore.Property) (err error)

func (*MeterEvent) Save

func (e *MeterEvent) Save() (ps []datastore.Property, err error)

func (*MeterEvent) Validator

func (e *MeterEvent) Validator() *val.Validator

Jump to

Keyboard shortcuts

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