all repos — homestead @ 2d8ae277e25117ab59eeb95c6ed25b34bcd75e4f

Code for my website

add two-week availability calendar

Alan Pearce
commit

2d8ae277e25117ab59eeb95c6ed25b34bcd75e4f

parent

0296be4cbce9b13896dd703e868029672e55fd8c

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) +}