utils

package
v0.0.0-...-815975e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSandboxID = "zzzzzzzzzzzzzzzzzzzz"
)

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(c *gin.Context, message string, statusCode int)

func MultiErrorHandler

func MultiErrorHandler(me openapi3.MultiError) error

MultiErrorHandler handles wrapped SecurityRequirementsError, so there are no multiple errors returned to the user.

func ParseCursor

func ParseCursor(cursor string) (time.Time, string, error)

func ParseMetadata

func ParseMetadata(ctx context.Context, metadata *string) (*map[string]string, error)

func ParseNextToken

func ParseNextToken(token *string) (time.Time, string, error)

func SandboxChangingStateMsg

func SandboxChangingStateMsg(sandboxID string, state sandbox.State) string

func SandboxNotFoundMsg

func SandboxNotFoundMsg(sandboxID string) string

func ShortID

func ShortID(compositeID string) (string, error)

func SortPaginatedSandboxesDesc

func SortPaginatedSandboxesDesc(sandboxes []PaginatedSandbox)

SortPaginatedSandboxesDesc sorts the sandboxes by StartedAt (descending), then by SandboxID (ascending) for stability

func UnwrapGRPCError

func UnwrapGRPCError(err error) error

Types

type Cursor

type Cursor struct {
	Time time.Time
	ID   string
}

Cursor represents a parsed pagination cursor

type NoOpWriter

type NoOpWriter struct{}

NoOpWriter is an io.Writer implementation that discards anything written to it.

func (*NoOpWriter) Write

func (nw *NoOpWriter) Write(p []byte) (n int, err error)

type PaginatedSandbox

type PaginatedSandbox struct {
	api.ListedSandbox

	PaginationTimestamp time.Time `json:"-"`
}

PaginatedSandbox extends the api.ListedSandbox with a timestamp to use for pagination

func FilterBasedOnCursor

func FilterBasedOnCursor(sandboxes []PaginatedSandbox, cursorTime time.Time, cursorID string) []PaginatedSandbox

func FilterSandboxesOnMetadata

func FilterSandboxesOnMetadata(sandboxes []PaginatedSandbox, metadata *map[string]string) []PaginatedSandbox

type Pagination

type Pagination[T any] struct {
	// contains filtered or unexported fields
}

Pagination handles pagination logic for list endpoints

func NewPagination

func NewPagination[T any](params PaginationParams, config PaginationConfig) (*Pagination[T], error)

NewPagination creates a new pagination instance from request parameters

func (*Pagination[T]) CursorID

func (p *Pagination[T]) CursorID() string

CursorID returns the cursor ID

func (*Pagination[T]) CursorTime

func (p *Pagination[T]) CursorTime() time.Time

CursorTime returns the cursor timestamp

func (*Pagination[T]) ProcessResultsWithHeader

func (p *Pagination[T]) ProcessResultsWithHeader(c *gin.Context, results []T, getTimestampAndID func(T) (time.Time, string)) []T

ProcessResultsWithHeader handles pagination and sets the X-Next-Token header in one call. This is a convenience method that combines ProcessResults and SetHeader.

func (*Pagination[T]) QueryLimit

func (p *Pagination[T]) QueryLimit() int32

QueryLimit returns the limit to use for database queries (limit + 1 to detect more results)

type PaginationConfig

type PaginationConfig struct {
	DefaultLimit int32
	MaxLimit     int32
	DefaultID    string // Default cursor ID when no token is provided (e.g., max UUID or max sandbox ID)
}

PaginationConfig holds configuration for pagination behavior

type PaginationParams

type PaginationParams struct {
	Limit     *int32
	NextToken *string
}

PaginationParams holds pagination parameters from the API request

type Result

type Result struct {
	Error error
}

type TemplateCounter

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

type TemplateSpawnCounter

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

func NewTemplateSpawnCounter

func NewTemplateSpawnCounter(ctx context.Context, tickerDuration time.Duration, dbClient *sqlcdb.Client) *TemplateSpawnCounter

func (*TemplateSpawnCounter) Close

func (t *TemplateSpawnCounter) Close(ctx context.Context)

func (*TemplateSpawnCounter) IncreaseTemplateSpawnCount

func (t *TemplateSpawnCounter) IncreaseTemplateSpawnCount(templateID string, time time.Time)

Jump to

Keyboard shortcuts

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