index

package
v0.0.0-...-5c8b67e Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigViperHook func(v *viper.Viper)

ConfigViperHook is a hook function meant for testing. This is called after the Viper instance is created but before the Config is loaded from the file system.

Functions

func GetIndexFs

func GetIndexFs() afero.Fs

GetIndexFs gets the current filesystem used by the Index. Meant for testing.

func SetIndexFs

func SetIndexFs(fs afero.Fs)

SetIndexFs sets the current filesystem used by the Index. Meant for testing. The behavior is undefined if this function is called between building an Index and adding Entries to it.

Types

type Config

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

Config represents the information need to load and store an Index on the filesystem.

func NewConfig

func NewConfig(configFile string) (Config, error)

NewConfig creates a Config from the given file.

func (Config) BaseName

func (c Config) BaseName() string

BaseName returns the base name that will be used when saving the Index.

func (Config) IgnoreDir

func (c Config) IgnoreDir(dir string) bool

IgnoreDir returns true if the given directory matches any of the ignored directory regular expressions.

func (Config) Root

func (c Config) Root() string

Root returns the root directory to be used by the Index.

func (Config) SavePath

func (c Config) SavePath() string

SavePath returns the directory where the Index will be saved.

func (Config) String

func (c Config) String() string

Formats the config as a String.

type Entry

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

Entry represents the data for a single file in the Index.

func (Entry) AsCsv

func (e Entry) AsCsv() string

AsCsv returns the entry as a comma separate string.

func (Entry) Hash

func (e Entry) Hash() string

Hash gets the hash of the file as a Base64 encoded string.

func (Entry) IsValid

func (e Entry) IsValid() bool

IsValid returns true if all the Entry's fields are set correctly.

func (Entry) LastMod

func (e Entry) LastMod() time.Time

LastMod gets the last modification time of the file.

func (Entry) Path

func (e Entry) Path() string

Path path of the file.

func (Entry) Size

func (e Entry) Size() int64

Size gets the size fo the file, in bytes.

func (Entry) String

func (e Entry) String() string

type Index

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

Index stores data for all files under a particular root directory.

func Load

func Load(path string) (*Index, error)

Load loads an existing index from the given path. Bad data in the Index will be logged but processing will continue to the end of the file.

func New

func New(root string) (*Index, error)

New creates a new, empty index rooted at the given path. This path _must_ use / as the separator.

func (*Index) Add

func (idx *Index) Add(path string, info os.FileInfo) error

Add the given file to the index after parsing it to a new Entry. The given path must include the index's root.

func (*Index) AddEntry

func (idx *Index) AddEntry(entry Entry) error

AddEntry adds the given Entry to the index.

func (*Index) ForEach

func (idx *Index) ForEach(f func(Entry))

ForEach Entry in the index, execute the given function.

func (*Index) Get

func (idx *Index) Get(path string) (Entry, bool)

Get the entry for the given path. This path _must be_ relative to the index root; see GetRelativePath()

func (*Index) GetRelativePath

func (idx *Index) GetRelativePath(path string) string

GetRelativePath returns the given path without the Index root.

func (*Index) Root

func (idx *Index) Root() string

Root returns the base path for the Entries in the index. Entry.Path should be combined with this path to get the absolute path of a file.

func (*Index) Size

func (idx *Index) Size() int

Size returns the number of Entries in the index.

func (*Index) Store

func (idx *Index) Store(path string) error

Store writes the index to the file system at the given path. This path should be a file. Callers are responsible for naming the file.

func (*Index) String

func (idx *Index) String() string

func (*Index) StringWithEntries

func (idx *Index) StringWithEntries() string

StringWithEntries returns the Index as JSON string that contains all of the Entries.

func (*Index) Timestamp

func (idx *Index) Timestamp() time.Time

Timestamp returns the datetime when this index was created.

Jump to

Keyboard shortcuts

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