-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mathieu Leduc-Hamel
committed
Mar 19, 2021
1 parent
d19c369
commit f9e2292
Showing
3 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package store | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
) | ||
|
||
type Local struct { | ||
prefix string | ||
} | ||
|
||
func NewLocal(prefix string) Store { | ||
return &Local{prefix: prefix} | ||
} | ||
|
||
func (l *Local) Setup(ctx context.Context) error { | ||
err := os.MkdirAll(l.prefix, os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Local) Persist(ctx context.Context, filename string, data string) error { | ||
dataAsByte := []byte(data) | ||
|
||
filenameWithPrefix := path.Join(s.prefix, filename) | ||
|
||
dirName := path.Dir(filenameWithPrefix) | ||
|
||
err := os.MkdirAll(dirName, os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = ioutil.WriteFile(filenameWithPrefix, dataAsByte, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |