...
1 package embeddedpostgres
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7 )
8
9
10
11 type CacheLocator func() (location string, exists bool)
12
13 func defaultCacheLocator(cacheDirectory string, versionStrategy VersionStrategy) CacheLocator {
14 return func() (string, bool) {
15 if cacheDirectory == "" {
16 cacheDirectory = ".embedded-postgres-go"
17 if userHome, err := os.UserHomeDir(); err == nil {
18 cacheDirectory = filepath.Join(userHome, ".embedded-postgres-go")
19 }
20 }
21
22 operatingSystem, architecture, version := versionStrategy()
23 cacheLocation := filepath.Join(cacheDirectory,
24 fmt.Sprintf("embedded-postgres-binaries-%s-%s-%s.txz",
25 operatingSystem,
26 architecture,
27 version))
28
29 info, err := os.Stat(cacheLocation)
30
31 if err != nil {
32 return cacheLocation, os.IsExist(err) && !info.IsDir()
33 }
34
35 return cacheLocation, !info.IsDir()
36 }
37 }
38
View as plain text