feat(vault_config): added vault configuration
This commit is contained in:
parent
56194470fb
commit
a8346e82f1
4 changed files with 89 additions and 1 deletions
|
|
@ -3,11 +3,17 @@ package handlers
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||
)
|
||||
|
||||
type initializeCommand struct {
|
||||
VaultPath string `json:"vaultPath"`
|
||||
TemplateDirectory string `json:"templateDirectory"`
|
||||
ScratchDirectory string `json:"scratchDirectory"`
|
||||
ScratchTemplate string `json:"scratchTemplate"`
|
||||
DailyDirectory string `json:"dailyDirectory"`
|
||||
DailyTemplate string `json:"dailyTemplate"`
|
||||
}
|
||||
|
||||
type InitializeHandler struct{}
|
||||
|
|
@ -23,6 +29,8 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
|||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
|
||||
err := persistence.InitializeDBContext(cmd.VaultPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
2
persistence/config/doc.go
Normal file
2
persistence/config/doc.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Package persistenceconfig provides configuration for persistence layer
|
||||
package persistenceconfig
|
||||
54
persistence/config/vault_configuration.go
Normal file
54
persistence/config/vault_configuration.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package persistenceconfig
|
||||
|
||||
import "path"
|
||||
|
||||
type VaultConfiguration struct {
|
||||
path string
|
||||
templateDirectory string
|
||||
scratches struct {
|
||||
directory string
|
||||
templateName string
|
||||
}
|
||||
dailyNotes struct {
|
||||
directory string
|
||||
templateName string
|
||||
}
|
||||
}
|
||||
|
||||
func NewVaultConfiguration(vaultPath, templateDirectory, scratchDirectory, scratchTemplate, dailyDirectory, dailyTemplate string) *VaultConfiguration {
|
||||
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory, scratches: struct {
|
||||
directory string
|
||||
templateName string
|
||||
}{
|
||||
directory: scratchDirectory,
|
||||
templateName: scratchTemplate,
|
||||
}, dailyNotes: struct {
|
||||
directory string
|
||||
templateName string
|
||||
}{
|
||||
directory: dailyDirectory,
|
||||
templateName: dailyTemplate,
|
||||
}}
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) VaultPath() string {
|
||||
return vc.path
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) ScratchTemplatePath() string {
|
||||
fileName := vc.fileTypeCheck(vc.scratches.templateName)
|
||||
return path.Join(vc.templateDirectory, fileName)
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) DailyTemplatePath() string {
|
||||
fileName := vc.fileTypeCheck(vc.dailyNotes.templateName)
|
||||
return path.Join(vc.templateDirectory, fileName)
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) fileTypeCheck(templateName string) string {
|
||||
fileType := path.Ext(templateName)
|
||||
if fileType != ".md" {
|
||||
return templateName + ".md"
|
||||
}
|
||||
return templateName
|
||||
}
|
||||
24
persistence/store/vault_store.go
Normal file
24
persistence/store/vault_store.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package store
|
||||
|
||||
import persistenceconfig "github.com/KristianJBorgwarth/dendrite.daemon/persistence/config"
|
||||
|
||||
type VaultStore struct {
|
||||
Config *persistenceconfig.VaultConfiguration
|
||||
}
|
||||
|
||||
var vaultStore *VaultStore
|
||||
|
||||
func NewVaultStore(vaultPath string) *VaultStore {
|
||||
if vaultStore != nil {
|
||||
return vaultStore
|
||||
}
|
||||
vaultStore = &VaultStore{}
|
||||
return vaultStore
|
||||
}
|
||||
|
||||
func GetVaultStore() *VaultStore {
|
||||
if vaultStore == nil {
|
||||
panic("VaultStore not initialized. Call NewVaultStore first.")
|
||||
}
|
||||
return vaultStore
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue