files

package
v0.7.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2018 License: MPL-2.0 Imports: 8 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")
)

blaf

Functions

func Exists

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

func ExistsFolder

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

func ReadFile

func ReadFile(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 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 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