ditto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ditto provides a Go client for provisioning ephemeral database copies from a running ditto server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCopy

func NewCopy(t testing.TB, opts ...Option) string

NewCopy creates an ephemeral database copy on the ditto server, registers t.Cleanup to delete it when the test finishes, and returns the connection string. Calls t.Fatal on any error.

Example:

dsn := ditto.NewCopy(t,
    ditto.WithServerURL("http://ditto.internal:8080"),
    ditto.WithToken(os.Getenv("DITTO_TOKEN")),
    ditto.WithTTL(10*time.Minute),
)

Types

type Client

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

Client talks to a ditto server to provision ephemeral database copies.

func New

func New(opts ...Option) *Client

New creates a Client. At minimum WithServerURL must be provided.

func (*Client) WithCopy

func (c *Client) WithCopy(ctx context.Context, fn func(dsn string) error) error

WithCopy creates a copy, calls fn with its connection string, then destroys the copy when fn returns — regardless of whether fn returns an error. This is the non-test counterpart to NewCopy; use it in scripts, CLIs, or any context where testing.TB is unavailable.

err := client.WithCopy(ctx, func(dsn string) error {
    return migrate(dsn)
})

type Option

type Option func(*Client)

Option configures a Client.

func WithServerURL

func WithServerURL(url string) Option

WithServerURL sets the base URL of the ditto server (e.g. "http://ditto.internal:8080").

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the lifetime of copies created by the client.

func WithToken

func WithToken(token string) Option

WithToken sets the Bearer token used to authenticate with the ditto server.

Jump to

Keyboard shortcuts

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