jot

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

README

Jot

Docs Build Status Go Report Card

The Go client library for JotFS, and associated CLI jot.

Library install

go get -u github.com/jotfs/jot

CLI install

Binaries

Download the latest binary from the releases page and extract. Example:

gzip -dc ./jot_darwin_amd64_v0.0.2.gz > jot
chmod +x jot
./jot --help
Source

jot may also be installed from source:

git clone https://github.com/jotfs/jot.git
cd jot
go install ./cmd/jot
jot --help

CLI configuration

The URL of your JotFS server may be passed using the --endpoint option. Alternatively, a config file may used with location at $HOME/.jot/config.toml or by setting the JOT_CONFIG_FILE environment variable.

Example config.toml:

[[profile]]
name = "default"
endpoint = "http://localhost:6777"

[[profile]]
name = "prod"
endpoint = "https://example.com

By default, jot will look for a profile named default. This may be overridden by setting the --profile option.

CLI reference

NAME:
   jot - A CLI tool for working with a JotFS server

USAGE:
   jot [global options] command [command options] [arguments...]

DESCRIPTION:
   
   jot will look for its configuration file at $HOME/.jot/config.toml 
   by default. Alternatively, its path may be specified by setting the 
   JOT_CONFIG_FILE environment variable, or with the --config option.
   The server endpoint URL may be overridden with the --endpoint option.

COMMANDS:
   cp       copy files to / from JotFS
   ls       list files
   rm       remove files
   admin    server administration commands
   version  output version info
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value     path to config file
   --profile value    config profile to use (default: "default")
   --endpoint value   set the server endpoint
   --tls_skip_verify  skip TLS certificate verification (default: false)
   --help, -h         show help (default: false)

License

Jot is licensed under the Apache 2.0 License. See LICENSE for details.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a file with a given ID cannot be found on the remote.

Functions

This section is empty.

Types

type Client

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

Client implements methods to interact with a JotFS server.

func New

func New(endpoint string, client *http.Client, opts *Options) (*Client, error)

New returns a new Client connecting to a JotFS server at the given endpoint URL. Optional configuration may be set with opts.

Example
package main

import (
	"net/http"

	"github.com/jotfs/jot"
)

func main() {
	jot.New("http://example.com:6777", http.DefaultClient, nil)
}
Output:

Example (Options)
package main

import (
	"net/http"

	"github.com/jotfs/jot"
)

func main() {
	jot.New("https://jotfs.example.com", http.DefaultClient, &jot.Options{
		Compression: jot.CompressNone,
	})
}
Output:

func (*Client) Copy

func (c *Client) Copy(src FileID, dst string) (FileID, error)

Copy makes a copy of a file from src to dst and returns the ID of the new file. Returns jotfs.ErrNotFound if the src does not exist.

func (*Client) CopyWithContext

func (c *Client) CopyWithContext(ctx context.Context, src FileID, dst string) (FileID, error)

CopyWithContext is the same as Copy with a user supplied context.

func (*Client) Delete

func (c *Client) Delete(file FileID) error

Delete deletes a file with a given ID. Returns jotfs.ErrNotFound if the file does not exist.

func (*Client) DeleteWithContext

func (c *Client) DeleteWithContext(ctx context.Context, file FileID) error

DeleteWithContext is the same as Delete with a user supplied context.

func (*Client) Download

func (c *Client) Download(file FileID, w io.Writer) error

Download retrieves a file and writes it to w. Returns jotfs.ErrNotFound if the file does not exist.

Example
package main

import (
	"bytes"
	"log"
	"net/http"
	"strings"

	"github.com/jotfs/jot"
)

func main() {
	client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
	if err != nil {
		log.Fatal(err)
	}

	r := strings.NewReader("Hello World!")
	fileID, err := client.Upload(r, "/notes/today.txt")
	if err != nil {
		log.Fatal(err)
	}

	var w bytes.Buffer
	err = client.Download(fileID, &w)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func (*Client) DownloadWithContext

func (c *Client) DownloadWithContext(ctx context.Context, file FileID, w io.Writer) error

DownloadWithContext is the same as Download with a user supplied context.

func (*Client) Head

func (c *Client) Head(name string, opts *HeadOpts) FileIterator

Head returns an iterator over the versions of a file with a given name.

func (*Client) HeadWithContext

func (c *Client) HeadWithContext(ctx context.Context, name string, opts *HeadOpts) FileIterator

HeadWithContext is the same as Head with a user supplied context.

func (*Client) List

func (c *Client) List(prefix string, opts *ListOpts) FileIterator

List returns an iterator over all versions of all files with a name matching the given prefix. Files may be excluded / included by supplying a ListOpts struct.

func (*Client) ListWithContext

func (c *Client) ListWithContext(ctx context.Context, prefix string, opts *ListOpts) FileIterator

ListWithContext is the same as List with a user supplied context.

func (*Client) Upload

func (c *Client) Upload(r io.Reader, dst string) (FileID, error)

Upload reads data from r and uploads it to the server, creating a new file version at dst. If a file already exists at the destination it will be kept if either:

  1. File versioning is currently enabled on the server
  2. File versioning was enabled when the existing version was uploaded

Otherwise the latest version will be overwritten.

Example
package main

import (
	"fmt"
	"log"
	"net/http"
	"strings"

	"github.com/jotfs/jot"
)

func main() {
	client, err := jot.New("http://localhost:6777", http.DefaultClient, nil)
	if err != nil {
		log.Fatal(err)
	}

	r := strings.NewReader("Hello World!")
	fileID, err := client.Upload(r, "/notes/today.txt")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("fileID = %x\n", fileID.Marshal())
}
Output:

func (*Client) UploadWithContext

func (c *Client) UploadWithContext(ctx context.Context, r io.Reader, dst string, mode CompressMode) (FileID, error)

UploadWithContext is the same as Upload with a user-supplied context and compression mode which overrides that set for the client.

type CompressMode

type CompressMode uint8

CompressMode represents the algorithm used to compress data.

const (
	// Zstandard compression
	CompressZstd CompressMode = 0
	// No compression
	CompressNone CompressMode = 1
)

Data compression modes

type FileID

type FileID [sumSize]byte

FileID represents a unique ID for a file on a JotFS server.

func UnmarshalFileID

func UnmarshalFileID(b []byte) (FileID, error)

UnmarshalFileID converts a byte slice to a FileID.

func (FileID) Marshal

func (s FileID) Marshal() []byte

Marshal serializes a FileID to a byte slice.

type FileInfo

type FileInfo struct {
	Name      string
	CreatedAt time.Time
	Size      uint64
	FileID    FileID
}

FileInfo stores metadata related to a file.

type FileIterator

type FileIterator interface {

	// Next returns the next FileInfo from the iterator. It returns io.EOF when the end
	// of the iterator is reached. The FileInfo is always invalid if the error is not nil.
	Next() (FileInfo, error)
}

FileIterator is an iterator over a stream of FileInfo returned by the methods List and Head.

type HeadOpts

type HeadOpts struct {
	// Limit is the maximum number of values to return from the iterator. Unlimited if
	// unspecified.
	Limit uint64

	// BatchSize is the maximum number of values to retrieve at a time from the remote.
	// Defaults to 1000.
	BatchSize uint64

	// Ascending, if set to true, returns values from the iterator in chronological
	// order. False by default, in which case values are returned in reverse-chronological
	// order
	Ascending bool
}

HeadOpts specify the options for the method Head.

type ListOpts

type ListOpts struct {
	// Exclude will exclude any files matching the glob pattern.
	Exclude string

	// Include forces inclusion of any files matched by the Exclude pattern. It is
	// ignored if Exclude is not provided.
	Include string

	// Limit is the maximum number of values to return from the iterator. Unlimited if
	// unspecified.
	Limit uint64

	// BatchSize is the maximum number of values to retrieve at a time from the remote.
	// Defaults to 1000.
	BatchSize uint64

	// Ascending, if set to true, returns values from the iterator in chronological
	// order. False by default, in which case values are returned in reverse-chronological
	// order
	Ascending bool
}

ListOpts specify the options for the method List.

type Options

type Options struct {
	// Compression, if set, overrides the default compression mode, CompressZstd.
	Compression CompressMode

	// CacheDir specifies the directory the client may cache temporary data files.
	// os.TempDir() by default. The directory must already exist.
	CacheDir string
}

Options specifies optional configuration for a Client.

Directories

Path Synopsis
cmd
jot
internal
protos
Package protos is a generated twirp stub package.
Package protos is a generated twirp stub package.

Jump to

Keyboard shortcuts

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