path

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: GPL-3.0 Imports: 14 Imported by: 17

Documentation

Index

Constants

View Source
const (
	OpCreate operation = iota
	OpCreateAbs
	OpStat
	OpExists
)
View Source
const (
	DirCreate dirOperation = iota
)
View Source
const (
	OpOpen validPathOperation = iota
)

Variables

View Source
var Error pathError

Functions

func CreateIf

func CreateIf(create Creatable, s string) (err error)

func SelectAll

func SelectAll(_ Pather) bool

func UseAsScanner

func UseAsScanner(r ReaderCreator, fn func(*bufio.Scanner) error) (err error)

UseAsScanner creates a ReaderCloser and wraps it inside a bufio.Scanner struct to be used by fn.

func UseReader

func UseReader(r ReaderCreator, fn func(io.Reader) error) (err error)

UseReader creates a ReadCloser object, applies the fn function to it (uses the resource), and finally closes it. This ensures that the error reported by the Close method is returned and not ignored and clearly denotes the lifetime of a ReadCloser instance.

func UseWriter

func UseWriter(w WriterCreator, fn func(io.Writer) error) (err error)

Types

type BufferedCreator

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

func (BufferedCreator) CreateReader

func (b BufferedCreator) CreateReader() (reader io.ReadCloser, err error)

type BufferedReadCloser

type BufferedReadCloser struct {
	io.ReadCloser
	*bufio.Reader
}

func (*BufferedReadCloser) Read

func (b *BufferedReadCloser) Read(p []byte) (n int, err error)

type ByModTime

type ByModTime []Valid

func (ByModTime) Len

func (b ByModTime) Len() int

func (ByModTime) Less

func (b ByModTime) Less(i, j int) bool

func (ByModTime) Swap

func (b ByModTime) Swap(i, j int)

type CloseError

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

func (CloseError) Error

func (ce CloseError) Error() (s string)

type Convertable

type Convertable interface {
	ToValid() (Valid, error)
	ToFile() (File, error)
	ToDir() (Dir, error)
	ToValidFile() (ValidFile, error)
}

type Creatable

type Creatable interface {
	SetPath(Path)
	Create(Path) error
}

type Dir

type Dir struct {
	Valid
}

func Cwd

func Cwd() (d Dir, err error)

func TempDir

func TempDir(prefix string) (d Dir, err error)

func TempDirIn

func TempDirIn(dir, prefix string) (d Dir, err error)

func (Dir) Chdir

func (d Dir) Chdir() (err error)

func (Dir) ReadDir

func (d Dir) ReadDir() (fi []os.FileInfo, err error)

func (Dir) Remove

func (d Dir) Remove() (err error)

func (*Dir) Set

func (d *Dir) Set(s string) (err error)

func (*Dir) UnmarshalJSON

func (d *Dir) UnmarshalJSON(b []byte) (err error)

type EmptyDir

type EmptyDir struct {
	Dir
}

func (EmptyDir) Create

func (_ EmptyDir) Create(p Path) (err error)

func (*EmptyDir) Set

func (e *EmptyDir) Set(s string) (err error)

func (*EmptyDir) SetPath

func (e *EmptyDir) SetPath(p Path)

func (*EmptyDir) UnmarshalJSON

func (e *EmptyDir) UnmarshalJSON(b []byte) (err error)

type EnumFilter

type EnumFilter func(int, Pather) (bool, error)

type ErrorFmt

type ErrorFmt interface {
	Fmt(Path) string
}

type Extension

type Extension string

func (Extension) Check

func (e Extension) Check(v ValidFile) (b bool)

func (Extension) Files

func (e Extension) Files(num int) (w WithExtension)

func (Extension) MustHave

func (e Extension) MustHave(v ValidFile) (err error)

type File

type File struct {
	Path
}

func (File) IfExists

func (f File) IfExists() (opt *ValidFile, err error)

func (File) ToValid

func (f File) ToValid() (vf ValidFile, err error)

type Filter

type Filter func(Pather) (bool, error)

type Filterer

type Filterer interface {
	Filter(Pather) (bool, error)
}

type FiltererPayload

type FiltererPayload struct {
	Filterer
}

func (*FiltererPayload) UnmarshalJSON

func (f *FiltererPayload) UnmarshalJSON(b []byte) (err error)

type Filters

type Filters []Filter

type From

type From interface {
	FromPath(p Pather) error
}

type Glob

type Glob func() ([]Valid, error)

type GlobPattern

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

func (GlobPattern) Glob

func (g GlobPattern) Glob() (gr GlobResult, err error)

func (*GlobPattern) UnmarshalJSON

func (g *GlobPattern) UnmarshalJSON(b []byte) (err error)

type GlobPatterns

type GlobPatterns map[string]GlobPattern

func (GlobPatterns) Get

func (g GlobPatterns) Get(key string, ext Extension) (f []ValidFile, err error)

type GlobResult

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

func (GlobResult) Into

func (g GlobResult) Into(in IndexedFrom) (err error)

func (GlobResult) Len

func (g GlobResult) Len() (n int)

type Globber

type Globber struct {
	Valid    Valid           `json:"path"`
	Pattern  string          `json:"pattern"`
	Filterer FiltererPayload `json:"select"`
}

func (Globber) Glob

func (g Globber) Glob() (v []Valid, err error)

type IndexedFrom

type IndexedFrom interface {
	GetFrom(ii int) From
}

type Like

type Like interface {
	Convertable
	Operations
}

type MustHaveExtension

type MustHaveExtension Extension

type NotExists

type NotExists string
const DoesNotExist NotExists = ""

func (NotExists) Error

func (e NotExists) Error() (s string)

type Operations

type Operations interface {
	fmt.Stringer
	Abs() (Like, error)
	Join(...string) Like
	Extension() Extension
	Exists() (bool, error)
	Glob() ([]Valid, error)
}

type Parts

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

func (Parts) ToPath

func (p Parts) ToPath() (pp Path)

func (*Parts) UnmarshalJSON

func (d *Parts) UnmarshalJSON(b []byte) (err error)

type Path

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

func Joined

func Joined(args ...string) Path

func New

func New(p string) Path

func (Path) Abs

func (p Path) Abs() (l Like, err error)

func (Path) AddExtension

func (p Path) AddExtension(ext string) (l Like)

func (Path) AsPath

func (p Path) AsPath() (rp Path)

* Make all structs that embedd Path trivially convertable back to Path.

func (Path) Base

func (p Path) Base() (l Like)

func (Path) Create

func (p Path) Create() (of *os.File, err error)

func (Path) Dir

func (p Path) Dir() (pp Path)

func (Path) Exists

func (p Path) Exists() (b bool, err error)

func (Path) Extension

func (p Path) Extension() (ext Extension)

func (Path) Fail

func (p Path) Fail(efmt ErrorFmt, err error) (Err error)

func (Path) GetPath

func (p Path) GetPath() string

func (Path) Glob

func (p Path) Glob() (v []Valid, err error)

func (Path) Hash

func (p Path) Hash(h hash.Hash)

func (Path) IfExists

func (p Path) IfExists() (optPath *Valid, err error)

func (Path) Into

func (p Path) Into(f From) (err error)

func (Path) Join

func (p Path) Join(args ...string) (l Like)

func (Path) Len

func (p Path) Len() int

func (Path) MarshalJSON

func (p Path) MarshalJSON() (b []byte, err error)

func (Path) Mkdir

func (p Path) Mkdir() (d Dir, err error)

func (Path) MustExist

func (p Path) MustExist() (err error)

func (Path) NoExtension

func (p Path) NoExtension() (l Like)

func (Path) Remove

func (p Path) Remove() (err error)

func (*Path) Set

func (p *Path) Set(s string) (err error)

func (Path) String

func (p Path) String() string

func (Path) ToDir

func (p Path) ToDir() (d Dir, err error)

func (Path) ToFile

func (p Path) ToFile() (f File, err error)

func (Path) ToValid

func (p Path) ToValid() (vp Valid, err error)

func (Path) ToValidFile

func (p Path) ToValidFile() (vf ValidFile, err error)

func (Path) Touch

func (p Path) Touch() (err error)

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(b []byte) (err error)

type Pather

type Pather interface {
	AsPath() Path
}

type ReaderCreator

type ReaderCreator interface {
	CreateReader() (r io.ReadCloser, err error)
}

ReadCreator represents an object that can create a ReadCloser.

type Retreiver

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

func NewRetreiver

func NewRetreiver(dir Dir, pattern string) (r Retreiver)

func (Retreiver) Format

func (r Retreiver) Format(args ...interface{}) (p File, err error)

func (Retreiver) Get

func (r Retreiver) Get() (vf ValidFile, err error)

func (Retreiver) Index

func (r Retreiver) Index(idx int) (vf ValidFile, err error)

func (Retreiver) Key

func (r Retreiver) Key(key string) (vf ValidFile, err error)

type Scanner

type Scanner struct {
	*bufio.Scanner
	*os.File
}

type SelectDir

type SelectDir struct{}

func (SelectDir) Filter

func (_ SelectDir) Filter(p Pather) (b bool, err error)

type SelectFile

type SelectFile struct{}

func (SelectFile) Filter

func (_ SelectFile) Filter(p Pather) (b bool, err error)

type Transform

type Transform func(Pather) (Pather, error)

type Transformer

type Transformer interface {
	Transform(Like) (Like, error)
}

type Transforms

type Transforms []Transform

type Valid

type Valid struct {
	Path
}

func (*Valid) FromPath

func (v *Valid) FromPath(p Pather) (err error)

func (Valid) IsDir

func (vp Valid) IsDir() (b bool, err error)

func (Valid) ModTime

func (vp Valid) ModTime() (t time.Time, err error)

func (Valid) Move

func (vp Valid) Move(dir Dir) (dst Valid, err error)

func (Valid) OlderThan

func (v Valid) OlderThan(vp Valid) (b bool, err error)

func (Valid) Open

func (vp Valid) Open() (of *os.File, err error)

func (Valid) Remove

func (vp Valid) Remove() (err error)

func (Valid) Rename

func (vp Valid) Rename(target fmt.Stringer) (dst Valid, err error)

func (*Valid) Set

func (v *Valid) Set(s string) (err error)

func (Valid) Stat

func (vp Valid) Stat() (fi os.FileInfo, err error)

func (Valid) ToFile

func (v Valid) ToFile() (vf ValidFile, err error)

func (*Valid) UnmarshalJSON

func (v *Valid) UnmarshalJSON(b []byte) (err error)

func (Valid) YoungerThan

func (v Valid) YoungerThan(vp Valid) (b bool, err error)

type ValidFile

type ValidFile struct {
	Valid
}

func (*ValidFile) FromPath

func (v *ValidFile) FromPath(p Pather) (err error)

func (ValidFile) LoadJson

func (vf ValidFile) LoadJson(val interface{}) (err error)

func (ValidFile) Move

func (vf ValidFile) Move(d Dir) (vfm ValidFile, err error)

func (ValidFile) ReadAll

func (vf ValidFile) ReadAll() (b []byte, err error)

func (ValidFile) Scanner

func (vf ValidFile) Scanner() (s Scanner, err error)

func (ValidFile) ToFile

func (vf ValidFile) ToFile() (f File)

func (ValidFile) Use

func (v ValidFile) Use(fn func(*os.File) error) (err error)

Use manages the `os.File` resource inside it's body allowing a a clousure or plain function acces to it.

type ValidFiles

type ValidFiles []ValidFile

func (ValidFiles) GetFrom

func (v ValidFiles) GetFrom(ii int) (f From)

type Validator

type Validator interface {
	Validate() error
}

type Valids

type Valids []Valid

func (Valids) Filter

func (v Valids) Filter(filt Filterer) (filtered Valids, err error)

func (Valids) Transform

func (v Valids) Transform(trans Transformer) (transformed Valids, err error)

type WithExtension

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

WithExtension represents a slice of files that have the proper extension. Implements the IndexedFrom interface. An easy way to generate a slice of valid file paths with the right extension.

func (WithExtension) Files

func (w WithExtension) Files() (files []ValidFile)

Files returns the valid file paths that have the right extension.

func (WithExtension) GetFrom

func (w WithExtension) GetFrom(ii int) (f From)

type WriterCreator

type WriterCreator interface {
	CreateWriter() (io.WriteCloser, error)
}

type WrongExtension

type WrongExtension struct {
	// The expected extension.
	Expected Extension
	// The extension we got.
	Got Extension
	// The file with the wrong extension.
	File ValidFile
}

WrongExtension represents an error that occurs when a valid file does not have the proper extension.

func (WrongExtension) Error

func (e WrongExtension) Error() (s string)

Jump to

Keyboard shortcuts

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