Skip to content

Commit 93dd117

Browse files
authored
fix(cache): initialize the wrapper explicitly (#181)
1 parent 1b11028 commit 93dd117

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

internal/cache/cache.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ type CacheWrap struct {
3434
}
3535

3636
func NewFileCache(path string) *FileCache {
37-
return &FileCache{path: path}
37+
return &FileCache{
38+
path: path,
39+
wrap: &CacheWrap{RefreshedAt: time.Unix(0, 0)},
40+
}
3841
}
3942

4043
func (c *FileCache) Read(out any) error {
@@ -48,7 +51,7 @@ func (c *FileCache) Read(out any) error {
4851
return err
4952
}
5053

51-
c.wrap = &CacheWrap{Data: out}
54+
c.wrap.Data = out
5255

5356
err = json.Unmarshal(content, c.wrap)
5457
if err == nil {
@@ -68,10 +71,6 @@ func (c *FileCache) Refresh(t time.Time) {
6871
}
6972

7073
func (c *FileCache) RefreshedAt() time.Time {
71-
if c.wrap == nil {
72-
return time.Unix(0, 0)
73-
}
74-
7574
return c.wrap.RefreshedAt
7675
}
7776

0 commit comments

Comments
 (0)