diff --git a/core/handlers/initialize_handler.go b/core/handlers/initialize_handler.go index c698f62..90be2d8 100644 --- a/core/handlers/initialize_handler.go +++ b/core/handlers/initialize_handler.go @@ -3,11 +3,14 @@ package handlers import ( "context" "encoding/json" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence/store" ) type initializeCommand struct { - VaultPath string `json:"vaultPath"` + VaultPath string `json:"vaultPath"` + TemplateDirectory string `json:"templateDirectory"` } type InitializeHandler struct{} @@ -23,7 +26,9 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any return nil, err } - err := persistence.InitializeDBContext(cmd.VaultPath) + store := store.NewVaultStore(cmd.VaultPath, cmd.TemplateDirectory) + + err := persistence.InitializeDBContext(store.Config.VaultPath()) if err != nil { return nil, err } diff --git a/dendrite b/dendrite index 3410aa4..48fff04 100755 Binary files a/dendrite and b/dendrite differ diff --git a/persistence/config/doc.go b/persistence/config/doc.go new file mode 100644 index 0000000..2e8b305 --- /dev/null +++ b/persistence/config/doc.go @@ -0,0 +1,2 @@ +// Package persistenceconfig provides configuration for persistence layer +package persistenceconfig diff --git a/persistence/config/vault_configuration.go b/persistence/config/vault_configuration.go new file mode 100644 index 0000000..006aac1 --- /dev/null +++ b/persistence/config/vault_configuration.go @@ -0,0 +1,24 @@ +package persistenceconfig + +import "path" + +type VaultConfiguration struct { + path string + templateDirectory string +} + +func NewVaultConfiguration(vaultPath, templateDirectory string) *VaultConfiguration { + return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory} +} + +func (vc *VaultConfiguration) VaultPath() string { + return vc.path +} + +func (vc *VaultConfiguration) fileTypeCheck(templateName string) string { + fileType := path.Ext(templateName) + if fileType != ".md" { + return templateName + ".md" + } + return templateName +} diff --git a/persistence/store/vault_store.go b/persistence/store/vault_store.go new file mode 100644 index 0000000..d64a8b1 --- /dev/null +++ b/persistence/store/vault_store.go @@ -0,0 +1,28 @@ +package store + +import persistenceconfig "github.com/KristianJBorgwarth/dendrite.daemon/persistence/config" + +type VaultStore struct { + Config *persistenceconfig.VaultConfiguration +} + +var vaultStore *VaultStore + +func NewVaultStore(vault, templateDir string) *VaultStore { + if vaultStore != nil { + return vaultStore + } + vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vault, templateDir)} + return vaultStore +} + +func GetVaultStore() *VaultStore { + if vaultStore == nil { + panic("VaultStore not initialized. Call NewVaultStore first.") + } + return vaultStore +} + +func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) { + vs.Config = &config +}