httpclient

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package httpclient provides a typed Go client for consuming the filer REST API.

Create a client with:

client, err := httpclient.New("http://localhost:8080/api/filer")
if err != nil {
   panic(err)
}

Then use the client to manage files:

// List all backends
backends, err := client.ListBackends(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MIMEByExt

func MIMEByExt(ext string) string

MIMEByExt returns the MIME type for a file extension, consulting wellKnownMIME first and then the system MIME database.

Types

type Client

type Client struct {
	*client.Client
}

Client is a filer HTTP client that wraps the base HTTP client and provides typed methods for interacting with the filer API.

func New

func New(url string, opts ...client.ClientOpt) (*Client, error)

New creates a new filer HTTP client with the given base URL and options. The url parameter should point to the filer API endpoint, e.g. "http://localhost:8080/api/filer".

func (*Client) CreateObject

func (c *Client) CreateObject(ctx context.Context, name string, req schema.CreateObjectRequest) (*schema.Object, error)

CreateObject uploads content using PUT, forwarding ContentType, ModTime and Meta as request headers.

func (*Client) CreateObjects

func (c *Client) CreateObjects(ctx context.Context, name string, fsys fs.FS, opts ...UploadOpt) ([]schema.Object, error)

CreateObjects walks fsys and uploads every matching file to the named backend as a single streaming multipart POST. To upload a subtree, pass fs.Sub(fsys, "subdir") as fsys. Options control the remote prefix, entry filter, pre-upload skip check, and progress callback; all are optional. By default, files that already exist remotely with the same size (and modtime when available) are skipped. Use WithCheck(nil) to disable this behaviour.

func (*Client) DeleteObject

func (c *Client) DeleteObject(ctx context.Context, name string, req schema.DeleteObjectRequest) (*schema.Object, error)

DeleteObject deletes a single object.

func (*Client) DeleteObjects

DeleteObjects deletes objects under a path prefix (recursive or non-recursive bulk delete).

func (*Client) GetObject

func (c *Client) GetObject(ctx context.Context, name string, req schema.GetObjectRequest) (*schema.Object, error)

GetObject retrieves metadata only for an object using HEAD (no body download).

func (*Client) GetObjects

func (c *Client) GetObjects(ctx context.Context, name string, reqs []schema.GetObjectRequest) ([]*schema.Object, error)

GetObjects fetches metadata for multiple objects concurrently using HEAD requests, with both goroutine count and in-flight requests capped at parallelHeads via a bounded worker pool. Results are returned in the same order as reqs. Any per-request errors are joined and returned alongside partial results.

func (*Client) ListBackends

func (c *Client) ListBackends(ctx context.Context) (*schema.BackendListResponse, error)

ListBackends returns a list of backend URLs from the filer API.

func (*Client) ListObjects

ListObjects returns a list of objects at the given backend name and optional path prefix.

func (*Client) ReadObject

func (c *Client) ReadObject(ctx context.Context, name string, req schema.ReadObjectRequest, fn func([]byte) error) (*schema.Object, error)

ReadObject downloads the content of an object using GET, calling fn with each chunk of data as it arrives from the server. The slice passed to fn is reused across calls; copy it if retained. Returns the object metadata; the returned *Object is always non-nil on success.

type UploadOpt

type UploadOpt func(*uploadOpts) error

UploadOpt is a functional option for CreateObjects.

func WithCheck

func WithCheck(fn func(fs.FileInfo, *schema.Object) bool) UploadOpt

WithCheck overrides the default skip check. The function receives the local fs.FileInfo and the remote schema.Object (nil when the object does not exist); return true to skip the upload for that file. Pass nil to disable skipping entirely.

func WithFilter

func WithFilter(fn func(fs.DirEntry) bool) UploadOpt

WithFilter sets a function that controls which entries are walked. Return false to skip the entry (and its subtree when it is a directory).

func WithPrefix

func WithPrefix(prefix string) UploadOpt

WithPrefix sets the remote destination prefix under which all uploaded files are stored. For example, WithPrefix("photos/2026") uploads a.txt as /photos/2026/a.txt. The default is the backend root.

func WithProgress

func WithProgress(fn func(index, count int, path string, written, bytes int64)) UploadOpt

WithProgress sets a callback that is invoked for each SSE byte-progress update and once per committed file. index is the 0-based file position; count is the total number of files in this upload batch (from the SSE start event). written and bytes are the per-file byte counters.

Jump to

Keyboard shortcuts

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