Help us shape the future of Go! Take the 2026 Go Developer Survey

virtualkey

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const GeneratedKeyPrefix = "vk-"

Variables

View Source
var (
	ErrVirtualKeyNotCarried    = errors.New("virtual key is not carried")
	ErrVirtualKeyNotConfigured = errors.New("virtual key is not configured")
)

Functions

func DecodeStoredVirtualKey

func DecodeStoredVirtualKey(data []byte) (any, error)

DecodeStoredVirtualKey decodes virtual key records.

func ExtractAPIKeys added in v0.2.0

func ExtractAPIKeys(r *http.Request) []string

ExtractAPIKeys returns every candidate virtual-key value carried by the request, in precedence order. A request may legitimately present a key in both the `x-api-key` header and the `Authorization: Bearer` header (Claude Code, for example, always sends both — the gateway virtual key in one and an unrelated upstream key in the other), so callers must try each candidate rather than trusting a single header. Empty and duplicate values are omitted.

func GenerateKey

func GenerateKey() (string, error)

Types

type VirtualKey

type VirtualKey struct {
	ID          string `json:"id"`
	Key         string `json:"key"`
	Tag         string `json:"tag,omitempty"`
	Description string `json:"description,omitempty"`
	Disabled    bool   `json:"disabled"`

	AllowedRouteIDs []string `json:"allowed_route_ids,omitempty"`

	StatusMessage string    `json:"status_message,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	ExpiresAt     time.Time `json:"expires_at,omitempty"`
}

VirtualKey represents a gateway consumer identity, not an upstream provider credential.

func (*VirtualKey) NormalizeTimestamps

func (key *VirtualKey) NormalizeTimestamps(now time.Time)

func (VirtualKey) Validate

func (key VirtualKey) Validate() error

func (VirtualKey) ValidateForRoute

func (key VirtualKey) ValidateForRoute(routeID string) error

type VirtualKeyListOptions

type VirtualKeyListOptions struct {
	Tag string
}

type VirtualKeyManager

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

func NewVirtualKeyManager

func NewVirtualKeyManager(store configstore.ConfigStore) *VirtualKeyManager

func (*VirtualKeyManager) Create

func (m *VirtualKeyManager) Create(ctx context.Context, key VirtualKey) error

func (*VirtualKeyManager) Delete

func (m *VirtualKeyManager) Delete(ctx context.Context, id string) error

func (*VirtualKeyManager) GetByID

func (m *VirtualKeyManager) GetByID(ctx context.Context, id string) (VirtualKey, error)

func (*VirtualKeyManager) GetByKey

func (m *VirtualKeyManager) GetByKey(ctx context.Context, key string) (VirtualKey, error)

func (*VirtualKeyManager) List

func (*VirtualKeyManager) Reset

func (m *VirtualKeyManager) Reset()

func (*VirtualKeyManager) Update

func (m *VirtualKeyManager) Update(ctx context.Context, id string, key VirtualKey) error

Jump to

Keyboard shortcuts

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