lettuce

package module
v0.0.0-...-af53a4b Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 24 Imported by: 0

README

= lettuce
Matt Nicholls <transientvariable@protonmail.com>
:keywords: golang,object storage,file system,fs,seaweedfs,s3,webdav
:experimental: true
:icons: font
:iconfont-cdn: //cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/fontawesome.min.css
:imagesdir: docs/image
:sectanchors: true
:source-highlighter: prettify
:toc: left
:toclevels: 3
:toc-title: Contents

ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]

CAUTION: WIP

== Overview

Go file system interface implementation for link:https://github.com/seaweedfs/seaweedfs[SeaweedFS].

== Installation

.Prerequisites
* The link:https://golang.org/dl/[Golang Runtime], version 1.24.x or later

[source%nowrap,bash]
----
❯ go get -u github.com/transientvariable/lettuce
----

== Usage

.Basic File Operations
[source%nowrap,go]
----
package main

import (
	"io/fs"

	"github.com/transientvariable/lettuce"
	"github.com/transientvariable/log-go"
)

func main() {
	fileName := "pirate-ships.txt"

	fsys, err := lettuce.New()
	if err != nil {
		log.Fatal("[main]", log.Err(err))
	}

	// Create a file object.
	log.Info("[main] creating file",
		log.String("name", fileName))
	f, err := fsys.Create(fileName)
	defer func(f fs.File) {
		if err := f.Close(); err != nil {
			log.Error("[main]", log.Err(err))
		}
	}(f)
	if err != nil {
		log.Fatal("[main]", log.Err(err))
	}

	// Use standard lib (io/fs) to retrieve a file
	// object status using lettuce as the file system
	// implementation.
	fi, err := fs.Stat(fsys, fileName)
	if err != nil {
		log.Fatal("[main]", log.Err(err))
	}
	log.Info("[main] file status",
		log.String("name", fi.Name()),
		log.Int64("size", fi.Size()))

	// Write data to file object.
	n, err := f.Write([]byte(`The quick brown fox jumps over the lazy dog\n`))
	if err != nil {
		log.Fatal("[main]", log.Err(err))
	}
	log.Info("[main] completed writing",
		log.String("name", fi.Name()),
		log.Int("bytes_written", n))

	// Retrieve file status again to show updated size.
	fi, err = fs.Stat(fsys, fileName)
	if err != nil {
		log.Fatal("[main]", log.Err(err))
	}
	log.Info("[main] file status (updated)",
		log.String("name", fi.Name()),
		log.Int64("size", fi.Size()))
}

----

== License
This project is licensed under the link:LICENSE[MIT License].

Documentation

Index

Constants

View Source
const (

	// GRPCKeepAlive configuration path.
	//
	// String: <root>.lettuce.client.grpc.keepAlive
	GRPCKeepAlive = clientGRPC + ".keepAlive"

	// GRPCKeepAliveTime configuration path.
	//
	// String: <root>.lettuce.client.grpc.keepAlive.time
	GRPCKeepAliveTime = GRPCKeepAlive + ".time"

	// GRPCKeepAliveTimeout configuration path.
	//
	// String: <root>.lettuce.client.grpc.keepAlive.timeout
	GRPCKeepAliveTimeout = GRPCKeepAlive + ".timeout"

	// GRPCKeepAlivePermitWithoutStream configuration path.
	//
	// String: <root>.lettuce.client.grpc.keepAlive.permitWithoutStream
	GRPCKeepAlivePermitWithoutStream = GRPCKeepAlive + ".permitWithoutStream"

	// GRPCMessageSizeMax configuration path.
	//
	// String: <root>.lettuce.client.grpc.messageSizeMax
	GRPCMessageSizeMax = clientGRPC + ".messageSizeMax"

	// GRPCMessageSizeMaxReceive configuration path.
	//
	// String: <root>.lettuce.client.grpc.messageSizeMax.receive
	GRPCMessageSizeMaxReceive = GRPCMessageSizeMax + ".receive"

	// GRPCMessageSizeMaxSend configuration path.
	//
	// String: <root>.lettuce.client.grpc.messageSizeMax.send
	GRPCMessageSizeMaxSend = GRPCMessageSizeMax + ".send"

	// GRPCSecurity configuration path.
	//
	// String: <root>.lettuce.client.grpc.security
	GRPCSecurity = clientGRPC + ".security"

	// GRPCSecurityTLS configuration path.
	//
	// String: <root>.lettuce.client.grpc.security.tls
	GRPCSecurityTLS = GRPCSecurity + ".tls"

	// GRPCSecurityTLSEnable configuration path.
	//
	// String: <root>.lettuce.client.grpc.security.tls.enable
	GRPCSecurityTLSEnable = GRPCSecurityTLS + ".enable"

	// GRPCSecurityTLSCertFile configuration path.
	//
	// String: <root>.lettuce.client.grpc.security.tls.certFile
	GRPCSecurityTLSCertFile = GRPCSecurityTLS + ".certFile"

	// GRPCSecurityTLSKeyFile configuration path.
	//
	// String: <root>.lettuce.client.grpc.security.tls.keyFile
	GRPCSecurityTLSKeyFile = GRPCSecurityTLS + ".keyFile"

	// SOCKS5Enable configuration path.
	//
	// value: <root>.lettuce.client.socks5.enable
	SOCKS5Enable = ".lettuce.client.socks5.enable"

	// SeaweedFSCluster configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster
	SeaweedFSCluster = seaweedFS + ".cluster"

	// SeaweedFSClusterLocal configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster.local
	SeaweedFSClusterLocal = SeaweedFSCluster + ".local"

	// SeaweedFSClusterFiler configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster.filer
	SeaweedFSClusterFiler = SeaweedFSCluster + ".filer"

	// SeaweedFSClusterFilerAddr configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster.filer.address
	SeaweedFSClusterFilerAddr = SeaweedFSClusterFiler + ".address"

	// SeaweedFSClusterMaster configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster.master
	SeaweedFSClusterMaster = SeaweedFSCluster + ".master"

	// SeaweedFSClusterMasterAddr configuration Path.
	//
	// String: <root>.lettuce.seaweedfs.cluster.master.address
	SeaweedFSClusterMasterAddr = SeaweedFSClusterMaster + ".address"
)

Variables

This section is empty.

Functions

func FSEntry

func FSEntry(fsys fs.FS, filerEntry *filer.Entry, options ...func(*fs.Entry)) (*fs.Entry, error)

FSEntry converts a filer.Entry to an fs.Entry.

func WithCluster

func WithCluster(c *cluster.Cluster) func(*Lettuce)

WithCluster sets the cluster for communicating with SeaweedFS backend services.

func WithContext

func WithContext(ctx context.Context) func(*File)

WithContext sets the context.Context used by the File.

func WithEntry

func WithEntry(e *filer.Entry) func(*File)

WithEntry sets the filer.Entry metadata for the File.

func WithGID

func WithGID(gid uint32) func(*Lettuce)

WithGID sets the default group ID to use when writing data.

func WithHTTPClient

func WithHTTPClient(c *gohttp.Client) func(*File)

WithHTTPClient sets the http.Client used for read/write operations for a File.

func WithUID

func WithUID(uid uint32) func(*Lettuce)

WithUID sets the default user ID to use when writing data.

Types

type File

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

File provides access to a single file or directory.

Implements the behavior defined by the fs.File and http.File interfaces.

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(b []byte) (int, error)

func (*File) ReadAt

func (f *File) ReadAt(b []byte, off int64) (int, error)

func (*File) ReadDir

func (f *File) ReadDir(n int) ([]gofs.DirEntry, error)

func (*File) ReadFrom

func (f *File) ReadFrom(r io.Reader) (int64, error)

func (*File) Readdir

func (f *File) Readdir(count int) ([]gofs.FileInfo, error)

func (*File) Seek

func (f *File) Seek(off int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (gofs.FileInfo, error)

func (*File) String

func (f *File) String() string

String returns a string representation of a File.

func (*File) Sync

func (f *File) Sync() error

func (*File) Write

func (f *File) Write(b []byte) (int, error)

type Lettuce

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

Lettuce is a file system provider that implements fs.FS using SeaweedFS for the storage backend.

func New

func New(options ...func(*Lettuce)) (*Lettuce, error)

New creates a new fs.FS backed by SeaweedFS using the provided options.

func (*Lettuce) Close

func (l *Lettuce) Close() error

Close releases any resources used by Lettuce.

func (*Lettuce) Cluster

func (l *Lettuce) Cluster() *cluster.Cluster

Cluster returns the cluster API used for performing operations against a SeaweedFS backend.

func (*Lettuce) Create

func (l *Lettuce) Create(name string) (fs.File, error)

Create ...

func (*Lettuce) Glob

func (l *Lettuce) Glob(pattern string) ([]string, error)

Glob ...

func (*Lettuce) Mkdir

func (l *Lettuce) Mkdir(name string, perm gofs.FileMode) error

Mkdir creates a new directory with the specified name and permission bits.

func (*Lettuce) MkdirAll

func (l *Lettuce) MkdirAll(path string, mode gofs.FileMode) error

MkdirAll ...

func (*Lettuce) Open

func (l *Lettuce) Open(name string) (gofs.File, error)

Open ...

func (*Lettuce) OpenFile

func (l *Lettuce) OpenFile(name string, flag int, mode gofs.FileMode) (fs.File, error)

OpenFile ...

func (*Lettuce) PathSeparator

func (l *Lettuce) PathSeparator() string

PathSeparator ...

func (*Lettuce) Provider

func (l *Lettuce) Provider() string

Provider ...

func (*Lettuce) ReadDir

func (l *Lettuce) ReadDir(name string) ([]gofs.DirEntry, error)

ReadDir ...

func (*Lettuce) ReadFile

func (l *Lettuce) ReadFile(name string) ([]byte, error)

ReadFile ...

func (*Lettuce) Remove

func (l *Lettuce) Remove(name string) error

Remove ...

func (*Lettuce) RemoveAll

func (l *Lettuce) RemoveAll(path string) error

RemoveAll ...

func (*Lettuce) Rename

func (l *Lettuce) Rename(oldpath string, newpath string) error

Rename ...

func (*Lettuce) Root

func (l *Lettuce) Root() (string, error)

Root ...

func (*Lettuce) Stat

func (l *Lettuce) Stat(name string) (gofs.FileInfo, error)

Stat ...

func (*Lettuce) String

func (l *Lettuce) String() string

String returns a string representation of Lettuce.

func (*Lettuce) Sub

func (l *Lettuce) Sub(dir string) (gofs.FS, error)

Sub ...

func (*Lettuce) WriteFile

func (l *Lettuce) WriteFile(name string, data []byte, mode gofs.FileMode) error

WriteFile ...

type WebDAV

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

WebDAV an implementation of the webdav.FileSystem using SeaweedFS for the storage backend.

func NewWebDAV

func NewWebDAV(let *Lettuce) (*WebDAV, error)

NewWebDAV creates a new webdav.FileSystem backed by the provided Lettuce instance.

func (*WebDAV) Close

func (w *WebDAV) Close() error

Close releases any resources used by WebDAV.

func (*WebDAV) Mkdir

func (w *WebDAV) Mkdir(ctx context.Context, name string, mode os.FileMode) error

func (*WebDAV) OpenFile

func (w *WebDAV) OpenFile(ctx context.Context, name string, flag int, mode os.FileMode) (webdav.File, error)

func (*WebDAV) RemoveAll

func (w *WebDAV) RemoveAll(ctx context.Context, name string) error

func (*WebDAV) Rename

func (w *WebDAV) Rename(ctx context.Context, oldName string, newName string) error

func (*WebDAV) Stat

func (w *WebDAV) Stat(ctx context.Context, name string) (os.FileInfo, error)

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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