mirror of
https://github.com/pikami/cosmium.git
synced 2026-01-10 13:05:45 +00:00
Added ability to load initial storage data
This commit is contained in:
31
internal/repositories/state.go
Normal file
31
internal/repositories/state.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
)
|
||||
|
||||
func LoadStateFS(filePath string) {
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading state JSON file: %v", err)
|
||||
}
|
||||
|
||||
var state repositorymodels.State
|
||||
if err := json.Unmarshal(data, &state); err != nil {
|
||||
log.Fatalf("Error unmarshalling state JSON: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Loaded state:")
|
||||
fmt.Printf("Databases: %d\n", len(state.Databases))
|
||||
fmt.Printf("Collections: %d\n", len(state.Collections))
|
||||
fmt.Printf("Documents: %d\n", len(state.Documents))
|
||||
|
||||
databases = state.Databases
|
||||
collections = state.Collections
|
||||
documents = state.Documents
|
||||
}
|
||||
@@ -110,3 +110,9 @@ type PartitionKeyRange struct {
|
||||
Ts int `json:"_ts"`
|
||||
Lsn int `json:"lsn"`
|
||||
}
|
||||
|
||||
type State struct {
|
||||
Databases []Database `json:"databases"`
|
||||
Collections []Collection `json:"collections"`
|
||||
Documents []Document `json:"documents"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user