add two-week availability calendar
1 file changed, 37 insertions(+), 0 deletions(-)
changed files
A internal/cache/cache.go
@@ -0,0 +1,37 @@ +package cache + +import ( + "os" + "path/filepath" + + "go.alanpearce.eu/homestead/internal/file" +) + +var home string +var Root *os.Root + +func init() { + var err error + home, err = os.UserCacheDir() + if err != nil { + panic("could not determine user cache directory: " + err.Error()) + } + + dir := filepath.Join(home, "homestead") + + if !file.Exists(dir) { + err = os.MkdirAll(dir, 0o750) + if err != nil { + panic("could not create cache sub-directory: " + err.Error()) + } + } + + Root, err = os.OpenRoot(dir) + if err != nil { + panic("could not open cache sub-directory: " + err.Error()) + } +} + +func JoinPath(path string) string { + return filepath.Join(Root.Name(), path) +}