restructuring; setting up basic webserver and templating
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
// a simple text file to the data as json.
|
||||
type FileDatastore struct {
|
||||
path string
|
||||
data map[string]string
|
||||
}
|
||||
|
||||
// Creates a new FileDatastore object, creating the storage file in the
|
||||
@@ -30,6 +31,10 @@ func NewFileDatastore(path string) (*FileDatastore, error) {
|
||||
// an error, if the file does not exit or the file content can not be
|
||||
// converted.
|
||||
func (fds *FileDatastore) readMapObj() (map[string]string, error) {
|
||||
if fds.data != nil {
|
||||
return fds.data, nil
|
||||
}
|
||||
|
||||
dat, err := os.ReadFile(fds.path)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
@@ -50,6 +55,8 @@ func (fds *FileDatastore) writeMapObj(m map[string]string) error {
|
||||
encoder := json.NewEncoder(file)
|
||||
if err := encoder.Encode(m); err != nil { return err }
|
||||
|
||||
fds.data = m
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user