workdir

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

README

workdir

This package provides utilties for creating and managing working directories. It defaults to the XDG suite of directory standards from freedesktop.org.

The functionality in this package should work on Linux, MacOS and the BSDs.

TODO

  • add a mechanism for root interactions
  • add Windows support

Documentation

Index

Constants

View Source
const (
	// DirTypeConfig is a directory used to store configuration. This is commonly
	// used to store application configs like yaml or json files used during
	// the bootstrapping phase of an application startup.
	DirTypeConfig dirType = iota
	// DirTypeCache is a directory used to store any temporary cache that is generated
	// by the application. This directory type can be used to store tokens when logging in,
	// or serialized cache such as large responses that you don't want to have to request again
	// for some amount of time. Anything in here should be considered temporary and can be removed
	// at any time.
	DirTypeCache
	// DirTypeData is a directory to store long term data. This data can be database files or assets
	// that need to later be extracted out into another location. Things in this directory should be
	// considered important and backed up.
	DirTypeData
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanupFunc

type CleanupFunc func() error

type Namespace

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

Namespace holds the directory parts that will be joined together to form a namespaced path segment in the final workdir.

func NewNamespace

func NewNamespace(parts []string) *Namespace

NewNamespace returns a new Namespace with the provided parts slice set

func (*Namespace) New

func (n *Namespace) New(dt dirType, opts Options) (*WorkDir, error)

New returns a new WorkDir under the context of dt (directory type) and allows for setting a namespace. Below is an example of its use: wd, _ := NewNamespace([]string{"foo", "bar"}).New(DirTypeConfig, Options{}) fmt.Println(wd.Path)

Out: /home/kyle/.config/foo/bar

type Options

type Options struct {
	// Mode is the octal filemode to use when creating each directory
	Mode os.FileMode
}

Options for changing the behavior of directory management

type WorkDir

type WorkDir struct {
	// Path is the absolute path to the directory requested.
	Path string
	// Cleanup is a function that will cleanup any directory and files under
	// Path.
	Cleanup CleanupFunc
}

WorkDir is a response type that contains the Path to a directory created by this package.

func New

func New(p string, opts Options) (*WorkDir, error)

New returns a new WorkDir or an error. An error is returned if p is empty. A standard cleanup function is made available so the caller can decide if they want to remove the directory created after they are done. Options allow additional control over the directory attributes.

Jump to

Keyboard shortcuts

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