os

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package os provides a few functions used throughout the grw package for interfacing with the local file system.

Index

Constants

View Source
const (
	// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
	//lint:ignore ST1003 keep identical to standard library
	O_RDONLY int = os.O_RDONLY // open the file read-only.
	//lint:ignore ST1003 keep identical to standard library
	O_WRONLY int = os.O_WRONLY // open the file write-only.
	//lint:ignore ST1003 keep identical to standard library
	O_RDWR int = os.O_RDWR // open the file read-write.
	// The remaining values may be or'ed in to control behavior.
	//lint:ignore ST1003 keep identical to standard library
	O_APPEND int = os.O_APPEND // append data to the file when writing.
	//lint:ignore ST1003 keep identical to standard library
	O_CREATE int = os.O_CREATE // create a new file if none exists.
	//lint:ignore ST1003 keep identical to standard library
	O_EXCL int = os.O_EXCL // used with O_CREATE, file must not exist.
	//lint:ignore ST1003 keep identical to standard library
	O_SYNC int = os.O_SYNC // open for synchronous I/O.
	//lint:ignore ST1003 keep identical to standard library
	O_TRUNC int = os.O_TRUNC // truncate regular writable file when opened.
)

Variables

View Source
var (
	Stdin  = os.Stdin
	Stdout = os.Stdout
	Stderr = os.Stderr
)
View Source
var (
	ErrPathMissing = errors.New("path missing")
)

Functions

func CheckURIRead

func CheckURIRead(uri string) error

func CheckURIWrite

func CheckURIWrite(uri string, appendToFile bool, overwrite bool) error

func Exit

func Exit(code int)

Exit causes the current program to exit with the given status code. Conventionally, code zero indicates success, non-zero an error. The program terminates immediately; deferred functions are not run.

func MkdirAll

func MkdirAll(p string, flag os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. Wraps the standard library os.MkdirAll function to add support for expanding the user's home directory. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil. Mkdirs expands the home directory and resolves the path given. Flag is the permissions flag, e.g., 0770.

func OpenDevice

func OpenDevice(name string) io.Writer

OpenDevice returns a pointer to the device indicated by name. Matches the following names as case insensitive:

  • stdout, /dev/stdout => os.Stdout
  • stderr, /dev/stderr => os.Stderr
  • stdin, /dev/stdin => os.Stdin
  • null, /dev/null => io.Discard

func OpenFile

func OpenFile(path string) (*os.File, error)

OpenFile returns wraps os.OpenFile

func Remove

func Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func Stat

func Stat(uri string) (bool, stat.Info, error)

Stat stats the given resource. Returns a bool indicating whether the file exists, file info, and an error if any. If the underlying error was a "does not exist" error, then the error is supressed and returns false, nil, nil If the underlying error was any other type of error, then the existence value is not guaranteed. Do check the error returned and do not ignore the error with "exists, _, _ := Stat(/path/tofile)".

Types

type Signal

type Signal interface {
	os.Signal
}

Jump to

Keyboard shortcuts

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