fs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fs provides functions for working with the file system as well as services that specifically deal with the file system.

Index

Constants

This section is empty.

Variables

View Source
var CreateDir = func(path string, mode os.FileMode) error {
	if !FileExists(path) {
		err := Root.MkdirAll(path, mode)
		if err != nil {
			return err
		}
	}

	return nil
}

CreateDir takes a path and a file mode, and it creates the path on Root with the given file mode. If there are any issues, an error is returned. Otherwise, nil is returned.

View Source
var DirectoryExists = func(path string) bool {
	if !FileExists(path) {
		return false
	}

	if !IsDir(path) {
		return false
	}

	return true
}

DirectoryExists takes a directory path and returns a bool. If the directory exists on Root, the result is true. Otherwise, it is false.

View Source
var FileExists = func(path string) bool {
	_, err := Root.Stat(path)

	if os.IsNotExist(err) {
		return false
	}

	return true
}

FileExists takes a file path and returns a bool. If the file exists on Root, the result is true. Otherwise, it is false.

View Source
var IsDir = func(path string) bool {
	info, err := Root.Stat(path)
	if err != nil {
		return false
	}

	return info.IsDir()
}

IsDir takes a path and returns a bool. If the path is a directory, the result is true. Otherwise, it is false.

View Source
var Root = afero.NewOsFs()

Root is an Afero Filesystem object used as a proxy to the real file system.

Functions

func Basename

func Basename(path string) string

Basename takes a file path and returns the actual filename.

func Executable

func Executable(path string) bool

Executable takes a file path and returns a bool. If the file's permissions have the executable bit enabled, the result is true. Otherwise, it is false.

func NewJobService

func NewJobService(path string, logger cronenberg.Logger) cronenberg.JobService

NewJobService takes a file path and a logger, using them to configure the returned JobService.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile takes a file path, reads that file, and returns a byte array of the file's contents and an error. If there are issues, the error is non-nil. Otherwise, the error is nil.

func Stat

func Stat(path string) (os.FileInfo, error)

Stat takes a path and returns both a file info object and an error. If there are issues along the way, the error is non-nil. Otherwise, the error is nil.

Types

type JobService

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

JobService is an object that knows how to load job definitions from a yaml file.

func (*JobService) All

func (service *JobService) All() []*cronenberg.Job

All reads the jobs from the service's file path and returns them as an array of Job objects. If there are issues along the way, the result is an empty array.

Jump to

Keyboard shortcuts

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