-
Notifications
You must be signed in to change notification settings - Fork 71
/
tile_cache.go
49 lines (42 loc) · 1.12 KB
/
tile_cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sm
import (
"os"
)
// TileCache provides cache information to the tile fetcher
type TileCache interface {
// Root path to store cached tiles in with no trailing slash.
Path() string
// Permission to set when creating missing cache directories.
Perm() os.FileMode
}
// TileCacheStaticPath provides a static path to the tile fetcher.
type TileCacheStaticPath struct {
path string
perm os.FileMode
}
// Path to the cache.
func (c *TileCacheStaticPath) Path() string {
return c.path
}
// Perm instructs the permission to set when creating missing cache directories.
func (c *TileCacheStaticPath) Perm() os.FileMode {
return c.perm
}
// NewTileCache stores cache files in a static path.
func NewTileCache(rootPath string, perm os.FileMode) *TileCacheStaticPath {
return &TileCacheStaticPath{
path: rootPath,
perm: perm,
}
}
// NewTileCacheFromUserCache stores cache files in a user-specific cache directory.
func NewTileCacheFromUserCache(perm os.FileMode) *TileCacheStaticPath {
path, err := os.UserCacheDir()
if err != nil {
path += "/go-staticmaps"
}
return &TileCacheStaticPath{
path: path,
perm: perm,
}
}