gobstore/load.go

32 lines
558 B
Go
Raw Permalink Normal View History

2025-01-12 09:51:51 +00:00
package gobstore
import (
"encoding/gob"
"errors"
"fmt"
"os"
)
// Load initializes the data from disk
func (j *GobStore[T]) Load() {
// no lock
fmt.Println(j.ROOT_DATA_PATH + j.path)
file, err := os.Open(j.ROOT_DATA_PATH + j.path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
fmt.Printf("Gob file does not exist: %s\n", j.path)
j.values = map[string]T{}
return
}
fmt.Println(err)
}
var res map[string]T
dec := gob.NewDecoder(file)
dec.Decode(&res)
if err != nil {
fmt.Println(err)
}
j.values = res
j.dirty = false
}