virtual_key

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateVirtualKeyRequest

type CreateVirtualKeyRequest struct {
	Name       string             `json:"name" validate:"required,min=1,max=255"`
	Providers  []llm.ProviderName `json:"providers" validate:"dive,oneof=OpenAI Anthropic Gemini xAI"`
	ModelIDs   []string           `json:"model_ids,omitempty"` // Changed to []string for model names
	RateLimits *RateLimits        `json:"rate_limits,omitempty"`
}

CreateVirtualKeyRequest represents the request to create a new virtual key

type RateLimit

type RateLimit struct {
	Unit  string `json:"unit" validate:"required,oneof=1min 1h 6h 12h 1d 1w 1mo"`
	Limit int64  `json:"limit" validate:"required,min=1"`
}

RateLimit represents a single rate limit configuration

type RateLimits

type RateLimits []RateLimit

RateLimits represents a list of rate limits that can be stored in JSONB

func (RateLimits) MarshalJSON

func (r RateLimits) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*RateLimits) Scan

func (r *RateLimits) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database/sql

func (*RateLimits) UnmarshalJSON

func (r *RateLimits) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (RateLimits) Value

func (r RateLimits) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database/sql

type UpdateVirtualKeyRequest

type UpdateVirtualKeyRequest struct {
	Name       *string             `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
	Providers  *[]llm.ProviderName `json:"providers,omitempty" validate:"omitempty,dive,oneof=OpenAI Anthropic Gemini xAI"`
	ModelIDs   *[]string           `json:"model_ids,omitempty"` // Changed to *[]string for model names
	RateLimits *RateLimits         `json:"rate_limits,omitempty"`
}

UpdateVirtualKeyRequest represents the request to update a virtual key

type VirtualKey

type VirtualKey struct {
	ID         uuid.UUID          `json:"id" db:"id"`
	Name       string             `json:"name" db:"name"`
	SecretKey  string             `json:"secret_key" db:"secret_key"`
	Providers  []llm.ProviderName `json:"providers" db:"-"`
	ModelNames []string           `json:"model_ids" db:"-"` // Keep json tag as model_ids for API compatibility
	RateLimits RateLimits         `json:"rate_limits" db:"rate_limits"`
	CreatedAt  time.Time          `json:"created_at" db:"created_at"`
	UpdatedAt  time.Time          `json:"updated_at" db:"updated_at"`
}

VirtualKey represents a virtual key configuration

type VirtualKeyRepo

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

VirtualKeyRepo handles database operations for virtual keys

func NewVirtualKeyRepo

func NewVirtualKeyRepo(db *sqlx.DB) *VirtualKeyRepo

NewVirtualKeyRepo creates a new virtual key repository

func (*VirtualKeyRepo) Create

Create creates a new virtual key with its providers and models

func (*VirtualKeyRepo) Delete

func (r *VirtualKeyRepo) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes a virtual key (cascade will delete relationships)

func (*VirtualKeyRepo) GetByID

func (r *VirtualKeyRepo) GetByID(ctx context.Context, id uuid.UUID) (*VirtualKey, error)

GetByID retrieves a virtual key by ID with its providers and models

func (*VirtualKeyRepo) GetByName

func (r *VirtualKeyRepo) GetByName(ctx context.Context, name string) (*VirtualKey, error)

GetByName retrieves a virtual key by name

func (*VirtualKeyRepo) GetBySecretKey

func (r *VirtualKeyRepo) GetBySecretKey(ctx context.Context, secretKey string) (*VirtualKey, error)

GetBySecretKey retrieves a virtual key by its secret key

func (*VirtualKeyRepo) List

func (r *VirtualKeyRepo) List(ctx context.Context) ([]*VirtualKey, error)

List retrieves all virtual keys with their providers and models

func (*VirtualKeyRepo) Update

Update updates a virtual key and its relationships

type VirtualKeyService

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

VirtualKeyService handles business logic for virtual keys

func NewVirtualKeyService

func NewVirtualKeyService(repo *VirtualKeyRepo) *VirtualKeyService

NewVirtualKeyService creates a new virtual key service

func (*VirtualKeyService) Create

Create creates a new virtual key

func (*VirtualKeyService) Delete

func (s *VirtualKeyService) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes a virtual key

func (*VirtualKeyService) GetByID

func (s *VirtualKeyService) GetByID(ctx context.Context, id uuid.UUID) (*VirtualKey, error)

GetByID retrieves a virtual key by ID

func (*VirtualKeyService) GetByName

func (s *VirtualKeyService) GetByName(ctx context.Context, name string) (*VirtualKey, error)

GetByName retrieves a virtual key by name

func (*VirtualKeyService) GetBySecretKey

func (s *VirtualKeyService) GetBySecretKey(ctx context.Context, secretKey string) (*VirtualKey, error)

GetBySecretKey retrieves a virtual key by its secret key

func (*VirtualKeyService) List

func (s *VirtualKeyService) List(ctx context.Context) ([]*VirtualKey, error)

List retrieves all virtual keys

func (*VirtualKeyService) Update

Update updates a virtual key

Jump to

Keyboard shortcuts

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