mirror of https://github.com/pikami/cosmium.git
Added ability to load initial storage data
This commit is contained in:
parent
a656f33009
commit
62ac9ddf6b
|
@ -13,6 +13,7 @@ func ParseFlags() {
|
||||||
explorerPath := flag.String("ExplorerDir", "/home/pk/pro/cosmos-explorer/dist", "Path to cosmos-explorer files")
|
explorerPath := flag.String("ExplorerDir", "/home/pk/pro/cosmos-explorer/dist", "Path to cosmos-explorer files")
|
||||||
tlsCertificatePath := flag.String("Cert", "../example.crt", "Hostname")
|
tlsCertificatePath := flag.String("Cert", "../example.crt", "Hostname")
|
||||||
tlsCertificateKey := flag.String("CertKey", "../example.key", "Hostname")
|
tlsCertificateKey := flag.String("CertKey", "../example.key", "Hostname")
|
||||||
|
initialDataPath := flag.String("InitialData", "", "Path to JSON containing initial state")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ func ParseFlags() {
|
||||||
Config.ExplorerPath = *explorerPath
|
Config.ExplorerPath = *explorerPath
|
||||||
Config.TLS_CertificatePath = *tlsCertificatePath
|
Config.TLS_CertificatePath = *tlsCertificatePath
|
||||||
Config.TLS_CertificateKey = *tlsCertificateKey
|
Config.TLS_CertificateKey = *tlsCertificateKey
|
||||||
|
Config.DataFilePath = *initialDataPath
|
||||||
|
|
||||||
Config.DatabaseAccount = Config.Host
|
Config.DatabaseAccount = Config.Host
|
||||||
Config.DatabaseDomain = Config.Host
|
Config.DatabaseDomain = Config.Host
|
||||||
|
|
|
@ -10,4 +10,5 @@ type ServerConfig struct {
|
||||||
Host string
|
Host string
|
||||||
TLS_CertificatePath string
|
TLS_CertificatePath string
|
||||||
TLS_CertificateKey string
|
TLS_CertificateKey string
|
||||||
|
DataFilePath string
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"`
|
Ts int `json:"_ts"`
|
||||||
Lsn int `json:"lsn"`
|
Lsn int `json:"lsn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type State struct {
|
||||||
|
Databases []Database `json:"databases"`
|
||||||
|
Collections []Collection `json:"collections"`
|
||||||
|
Documents []Document `json:"documents"`
|
||||||
|
}
|
||||||
|
|
5
main.go
5
main.go
|
@ -5,11 +5,16 @@ import (
|
||||||
|
|
||||||
"github.com/pikami/cosmium/api"
|
"github.com/pikami/cosmium/api"
|
||||||
"github.com/pikami/cosmium/api/config"
|
"github.com/pikami/cosmium/api/config"
|
||||||
|
"github.com/pikami/cosmium/internal/repositories"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.ParseFlags()
|
config.ParseFlags()
|
||||||
|
|
||||||
|
if config.Config.DataFilePath != "" {
|
||||||
|
repositories.LoadStateFS(config.Config.DataFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
router := api.CreateRouter()
|
router := api.CreateRouter()
|
||||||
router.RunTLS(
|
router.RunTLS(
|
||||||
fmt.Sprintf(":%d", config.Config.Port),
|
fmt.Sprintf(":%d", config.Config.Port),
|
||||||
|
|
Loading…
Reference in New Issue