client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client is the typed Go client of the motte store and control planes.

Index

Constants

View Source
const DefaultBudget = 2 * time.Second

DefaultBudget is the time limit of one call unless WithBudget sets another.

Variables

View Source
var (
	ErrNotConfigured      = errors.New("motte: not configured")
	ErrNotFound           = errors.New("motte: not found")
	ErrGenerationConflict = errors.New("motte: generation conflict")
	ErrClaimLost          = errors.New("motte: claim lost")
	ErrObjectInvalid      = errors.New("motte: object invalid")
	ErrObjectTooLarge     = errors.New("motte: object too large")
	ErrRepoForbidden      = errors.New("motte: repository forbidden")
	ErrWorkspaceConflict  = errors.New("motte: workspace conflict")
	ErrWorkspaceDeleted   = errors.New("motte: workspace deleted")
	ErrUnauthorized       = errors.New("motte: unauthorized")
	ErrInvalidBody        = errors.New("motte: invalid body")
	ErrInternal           = errors.New("motte: internal error")
	// ErrRedirect is the error of a 3xx answer. The client follows no redirect, so a grant never leaves the base URL.
	ErrRedirect = errors.New("motte: unexpected redirect")
	// ErrUnexpected is the error of a failure answer that carries no wire error body.
	ErrUnexpected = errors.New("motte: unexpected response")
)

Functions

func CurrentRef

func CurrentRef(err error) (api.Ref, bool)

CurrentRef returns the stored ref that a ref generation conflict carries.

Types

type Client

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

Client calls one store. A grant has one scope, so a caller holds one Client for each scope it uses. A Client is safe for concurrent use.

func New

func New(baseURL string, grant GrantFunc, opts ...Option) *Client

New returns a client of the store at baseURL.

func (*Client) Blobs

func (c *Client) Blobs(ctx context.Context, shas []string) ([][]byte, error)

Blobs returns the contents of the blobs, in the order of shas.

func (*Client) Claim

func (c *Client) Claim(ctx context.Context, workspace string, req api.ClaimRequest) (api.ClaimResponse, error)

Claim binds or raises the epoch of a workspace and returns its stored state.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, sha string) (api.Commit, error)

Commit returns the root tree and time of a commit.

func (*Client) CreateRepo

func (c *Client) CreateRepo(ctx context.Context, name, owner string) (string, error)

CreateRepo creates a repository with a root commit under main and returns its path.

func (*Client) DeleteRef

func (c *Client) DeleteRef(ctx context.Context, name string, expect int64) error

DeleteRef deletes the ref when its stored generation is expect.

func (*Client) DeleteWorkspace

func (c *Client) DeleteWorkspace(ctx context.Context, workspace string) error

DeleteWorkspace deletes a workspace. It is idempotent.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context, workspace string, req api.FlushRequest) error

Flush stores the state of a workspace under its claim epoch.

func (*Client) Has

func (c *Client) Has(ctx context.Context, shas []string) ([]bool, error)

Has reports for each sha whether the repository holds it.

func (*Client) ImportPack

func (c *Client) ImportPack(ctx context.Context, packID string, index, pack []byte) error

ImportPack stores a pack and its v2 index. packID is the lowercase hex SHA-256 of pack.

func (*Client) Object

func (c *Client) Object(ctx context.Context, sha string) (Object, error)

Object returns the type and content of one object.

func (*Client) Op

func (c *Client) Op(ctx context.Context, kind, id string) ([]byte, error)

Op returns one op-log object of the workspace.

func (*Client) OpHeads

func (c *Client) OpHeads(ctx context.Context) (api.OpHeads, error)

OpHeads returns the head set of the op log of the workspace.

func (*Client) PutObjects

func (c *Client) PutObjects(ctx context.Context, objs []Object) ([]string, error)

PutObjects stores the objects and returns their names.

func (*Client) PutOp

func (c *Client) PutOp(ctx context.Context, kind, id string, data []byte) error

PutOp stores one op-log object of the workspace. kind is the op kind of the store.

func (*Client) Ref

func (c *Client) Ref(ctx context.Context, name string) (api.Ref, error)

Ref returns one ref.

func (*Client) Refs

func (c *Client) Refs(ctx context.Context) ([]api.Ref, error)

Refs lists the refs of the repository.

func (*Client) Repo

func (c *Client) Repo(ctx context.Context, path string) (api.Repo, error)

Repo returns one repository.

func (*Client) Repos

func (c *Client) Repos(ctx context.Context) ([]api.Repo, error)

Repos lists the repositories, newest first.

func (*Client) SetWorkspace

func (c *Client) SetWorkspace(ctx context.Context, op, commit string, generation int64) error

SetWorkspace reports the op and commit of the workspace. generation is that of the op-heads swap of op.

func (*Client) SwapOpHeads

func (c *Client) SwapOpHeads(ctx context.Context, expectGeneration int64, heads []string) (api.OpHeads, error)

SwapOpHeads replaces the head set when the stored generation is expectGeneration. Use 0 for the first write.

func (*Client) SwapRef

func (c *Client) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)

SwapRef points the ref at commit when its stored generation is expect. Use 0 to create the ref. A conflict is ErrGenerationConflict, and CurrentRef returns the stored ref.

func (*Client) Trees

func (c *Client) Trees(ctx context.Context, sha string, maxEntries int) (api.Trees, error)

Trees returns the tree sha and the trees under it, at most maxEntries entries in all. Zero takes the server default.

type Error

type Error struct {
	Status  int
	Code    api.Code
	Message string
	Details map[string]any
	// contains filtered or unexported fields
}

Error is a failure answer of the store. errors.Is matches the sentinel of its code.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type GrantFunc

type GrantFunc func(ctx context.Context) (string, error)

GrantFunc returns the bearer grant of one call. The client calls it before each request.

func StaticGrant

func StaticGrant(token string) GrantFunc

StaticGrant returns a GrantFunc that always answers token.

type Object

type Object struct {
	Type string
	Data []byte
}

Object is one git object. Type is commit, tree, blob or tag.

type Option

type Option func(*Client)

func WithBudget

func WithBudget(d time.Duration) Option

WithBudget sets the time limit of one call. Zero or less removes the limit; a deadline on the call context still applies.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient sets the transport. The client still follows no redirect.

Jump to

Keyboard shortcuts

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