files

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: MPL-2.0 Imports: 9 Imported by: 73

Documentation

Overview

Package files implements utility routines for finding and reading files.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDirNotFound = errors.New("no directory found during walk")
	ErrStopWalk    = errors.New("WalkUp: stop")
)

Functions

func Exists

func Exists(pathElems ...string) (bool, error)

func ExistsFolder

func ExistsFolder(pathElems ...string) (bool, error)

func Read added in v0.7.0

func Read(pathElems ...string) ([]byte, error)

func ReadJSON

func ReadJSON(v interface{}, pathElems ...string) error

ReadJSON reads and unmarshals a file as if it contained JSON.

func ReadTOML added in v0.7.0

func ReadTOML(v interface{}, pathElems ...string) error

ReadTOML reads and unmarshals a file as if it contained TOML.

func ReadUnmarshal

func ReadUnmarshal(unmarshal UnmarshalFunc, v interface{}, pathElems ...string) error

ReadUnmarshal reads a file and then unmarshals its contents using an UnmarshalFunc.

func ReadXML added in v0.7.0

func ReadXML(v interface{}, pathElems ...string) error

ReadXML reads and unmarshals a file as if it contained XML.

func ReadYAML added in v0.7.0

func ReadYAML(v interface{}, pathElems ...string) error

ReadYAML reads and unmarshals a file as if it contained YAML.

func Rm added in v0.7.0

func Rm(pathElems ...string) error

func WalkUp added in v0.7.0

func WalkUp(startdir string, walker WalkUpFunc) (string, error)

WalkUp takes a starting directory and a WalkUpFunc, and calls the function, passing each ancestor of the starting directory in upwards order until the filesystem root is reached.

If the function returns ErrStopWalk, then WalkUp stops and returns the current directory name. If the function returns any other error, then WalkUp stops and that error is returned as the error of WalkUp. If ErrStopWalk is never returned, WalkUp returns ErrDirNotFound.

Types

type UnmarshalFunc

type UnmarshalFunc func(data []byte, v interface{}) error

An UnmarshalFunc is a function for unmarshalling bytes into values.

type WalkUpFunc added in v0.7.0

type WalkUpFunc func(dir string) error

A WalkUpFunc takes a directory and returns an error.

Jump to

Keyboard shortcuts

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