Documentation ¶
Overview ¶
Package datadir manages the data directories. This includes persisted data such as state as well as ephemeral data such as cache and runtime files.
This package is aware of the data model presented and provides easy helpers to create app-specific, component-specific, etc. data directories.
This package is the result of lessons learned from reimplementing "data directories" for projects such as Vagrant and Terraform. Those projects managed a list of directories directly in the CLI, forcing a lot of code to be aware of paths and making it hard to implement operations on those paths such as pruning, migration, compression, etc. As an evolution, we create the "datadir" package which has deep knowledge of the software data model and consumers interact using higher level APIs rather than direct filesystem manipulation. This gives us more room to introduce improvements in the future that broadly impact the application without having to make those changes in many places.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
Dir
}
Component is an implementation of Dir that encapsulates the directories for a specific component
type Dir ¶
type Dir interface { // CacheDir returns the path to a folder that can be used for // cache data. This directory may not be empty if a previous run // stored data, but it may also be emptied at any time between runs. CacheDir() path.Path // DataDir returns the path to a folder that can be used for data // storage DataDir() path.Path // ConfigDir is the path to a folder that can be used for storing // configuration type information. ConfigDir() path.Path // TempDir returns the path to a folder that can be used for temporary // data storage. Directory is routinely cleaned. TempDir() path.Path }
Dir is the interface implemented so that consumers can store data locally in a consistent way.
func NewBasicDir ¶
NewBasicDir creates a Dir implementation with a manually specified set of directories.
func NewScopedDir ¶
NewScopedDir creates a ScopedDir for the given parent at the relative child path of path. The caller should take care that multiple scoped dirs with overlapping paths are not created, since they could still collide.
type Project ¶
type Project struct {
Dir
}
Project is an implementation of Dir that encapsulates the directory for an entire project, including multiple apps.
The paths returned by the Dir interface functions will be project-global. This means that the data is shared by all applications in the project.