multipath

package module
v2.0.0-alpha.11 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MPL-2.0 Imports: 6 Imported by: 4

README

go-multipath

Go Reference

A simple library for accessing files from multiple fs.FS sources as a single, unified FS. It conforms to the FS, ReadDirFS, ReadFileFS, StatFS, and GlobFS interfaces.

import (
  "os"

  "github.com/kettek/go-multipath/v2"
)

func main() {
  var files multipath.FS

  files.AddFS(os.DirFS("dir_a")) // has "myFile"
  files.AddFS(os.DirFS("dir_b")) // has "myFile"

  file, err := files.Open("myFile")
  if err != nil {
    panic(err)
  }
  defer file.Close()

  // Do stuff with file, which would be sourced from "dir_b".
}

Documentation

Index

Constants

View Source
const (
	FirstPriority = 0
	LastPriority  = -1
)

These are our priorities.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS is a container for multiple fs.FS conforming items.

func (*FS) AddFS

func (m *FS) AddFS(p fs.FS)

AddFS adds the given fs to the beginning of the filesystems list.

func (*FS) Clean

func (m *FS) Clean(loc string) string

Clean cleans a path to remove access to unsafe directories.

func (FS) Glob

func (m FS) Glob(pattern string) ([]string, error)

Glob returns the names of all files matching pattern, providing an implementation of the top-level Glob function.

func (*FS) InsertFS

func (m *FS) InsertFS(p fs.FS, priority int)

InsertFS adds the given FS to the filesystems list with a given priority. If priority is FirstPriority, it is added to the beginning of the filesystems list. If it is LastPriority, it is added at the end of the filesystems list. Other priority values will be treated as indices to insert at. If the priority is beyond the length of filesystems, it will be added to the end of the filesystems list.

func (FS) Open

func (m FS) Open(name string) (fs.File, error)

Open opens the named file.

func (FS) ReadDir

func (m FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries sorted by filename.

func (FS) ReadFile

func (m FS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents.

func (*FS) RemoveFS

func (m *FS) RemoveFS(p fs.FS) bool

RemoveFS removes the given FS from the filesystems list.

func (FS) Stat

func (m FS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file from the file system.

func (*FS) Walk

func (m *FS) Walk(path string, walkFn fs.WalkDirFunc) (err error)

Walk traverses the directory structure, calling wallkFn on each.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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