gotch/init.go

34 lines
550 B
Go
Raw Permalink Normal View History

package gotch
import (
"fmt"
"log"
"os"
)
var (
2022-03-09 10:36:43 +00:00
CachedDir string = "NOT_SETTING"
gotchEnvKey string = "GOTCH_CACHE"
)
func init() {
homeDir := os.Getenv("HOME")
2022-03-09 10:36:43 +00:00
CachedDir = fmt.Sprintf("%s/.cache/gotch", homeDir) // default dir: "{$HOME}/.cache/gotch"
initEnv()
2022-02-24 02:07:38 +00:00
// log.Printf("INFO: CacheDir=%q\n", CacheDir)
}
func initEnv() {
val := os.Getenv(gotchEnvKey)
if val != "" {
2022-03-09 10:36:43 +00:00
CachedDir = val
}
2022-03-09 10:36:43 +00:00
if _, err := os.Stat(CachedDir); os.IsNotExist(err) {
if err := os.MkdirAll(CachedDir, 0755); err != nil {
log.Fatal(err)
}
}
}