types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 5 Imported by: 0

README

types

Generic data structures used across the relay system.

Key Types

  • PriceData -- holds pricing ratios and quota information for a model (model price, completion ratio, cache ratio, image/audio ratios, group ratio, custom "other" ratios). Supports applying and removing other-ratio multipliers on float and decimal.Decimal values.
  • GroupRatioInfo -- group-level pricing ratio with optional special ratio.
  • RWMap[K, V] -- generic concurrent read/write map with sync.RWMutex. Supports JSON marshal/unmarshal, Get, Set, AddAll, Clear, ReadAll, Len, and LoadFromJsonString.
  • Set[T] -- generic set with Add, Remove, Contains, Len, and Items.

Usage

m := types.NewRWMap[string, int]()
m.Set("a", 1)
val, ok := m.Get("a")

s := types.NewSet[string]()
s.Add("x")
s.Contains("x") // true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFromJsonString

func LoadFromJsonString[K comparable, V any](m *RWMap[K, V], jsonStr string) error

func LoadFromJsonStringWithCallback

func LoadFromJsonStringWithCallback[K comparable, V any](m *RWMap[K, V], jsonStr string, onSuccess func()) error

Types

type GroupRatioInfo

type GroupRatioInfo struct {
	GroupRatio        float64
	GroupSpecialRatio float64
	HasSpecialRatio   bool
}

type PriceData

type PriceData struct {
	FreeModel            bool
	ModelPrice           float64
	ModelRatio           float64
	CompletionRatio      float64
	CacheRatio           float64
	CacheCreationRatio   float64
	CacheCreation5mRatio float64
	CacheCreation1hRatio float64
	ImageRatio           float64
	AudioRatio           float64
	AudioCompletionRatio float64

	UsePrice          bool
	Quota             int // 按次计费的最终额度(MJ / Task)
	QuotaToPreConsume int // 按量计费的预消耗额度
	GroupRatioInfo    GroupRatioInfo
	// contains filtered or unexported fields
}

func (*PriceData) AddOtherRatio

func (p *PriceData) AddOtherRatio(key string, ratio float64)

func (*PriceData) ApplyOtherRatiosToDecimal

func (p *PriceData) ApplyOtherRatiosToDecimal(value decimal.Decimal) decimal.Decimal

func (*PriceData) ApplyOtherRatiosToFloat

func (p *PriceData) ApplyOtherRatiosToFloat(value float64) float64

func (*PriceData) HasOtherRatio

func (p *PriceData) HasOtherRatio(key string) bool

func (*PriceData) OtherRatioMultiplier

func (p *PriceData) OtherRatioMultiplier() float64

func (*PriceData) OtherRatios

func (p *PriceData) OtherRatios() map[string]float64

func (*PriceData) RemoveOtherRatiosFromFloat

func (p *PriceData) RemoveOtherRatiosFromFloat(value float64) float64

func (*PriceData) ReplaceOtherRatios

func (p *PriceData) ReplaceOtherRatios(ratios map[string]float64) bool

func (*PriceData) ToSetting

func (p *PriceData) ToSetting() string

type RWMap

type RWMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRWMap

func NewRWMap[K comparable, V any]() *RWMap[K, V]

func (*RWMap[K, V]) AddAll

func (m *RWMap[K, V]) AddAll(other map[K]V)

func (*RWMap[K, V]) Clear

func (m *RWMap[K, V]) Clear()

func (*RWMap[K, V]) Get

func (m *RWMap[K, V]) Get(key K) (V, bool)

func (*RWMap[K, V]) Len

func (m *RWMap[K, V]) Len() int

func (*RWMap[K, V]) MarshalJSON

func (m *RWMap[K, V]) MarshalJSON() ([]byte, error)

func (*RWMap[K, V]) MarshalJSONString

func (m *RWMap[K, V]) MarshalJSONString() string

func (*RWMap[K, V]) ReadAll

func (m *RWMap[K, V]) ReadAll() map[K]V

func (*RWMap[K, V]) Set

func (m *RWMap[K, V]) Set(key K, value V)

func (*RWMap[K, V]) UnmarshalJSON

func (m *RWMap[K, V]) UnmarshalJSON(b []byte) error

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable]() *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(item T)

func (*Set[T]) Contains

func (s *Set[T]) Contains(item T) bool

func (*Set[T]) Items

func (s *Set[T]) Items() []T

func (*Set[T]) Len

func (s *Set[T]) Len() int

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T)

Jump to

Keyboard shortcuts

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