Added API (preliminary, mostly for decoupling and separation of concerns) Chats are *mostly* implemented as far as metadata goes. Datastore confusion persists.
52 lines
960 B
Go
52 lines
960 B
Go
// Data hive.
|
|
|
|
package app
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"go.destrealm.net/vfs"
|
|
)
|
|
|
|
const (
|
|
DATASTORE_CHATS = "./data/chats"
|
|
DATASTORE_TRANSLATIONS = "./data/translations"
|
|
DATASTORE_VERSES = "./data/verses"
|
|
)
|
|
|
|
type datastore struct {
|
|
storage *storage
|
|
mut *sync.RWMutex
|
|
}
|
|
|
|
func newDataStore(root vfs.VFS) (ds *datastore, err error) {
|
|
ds = &datastore{
|
|
mut: &sync.RWMutex{},
|
|
storage: &storage{},
|
|
}
|
|
|
|
if chats, err := root.Chroot(DATASTORE_CHATS); err != nil {
|
|
return nil, err
|
|
} else {
|
|
ds.storage.chats = chats.Mutable()
|
|
}
|
|
if ds.storage.translations, err = root.Chroot(DATASTORE_TRANSLATIONS); err == nil {
|
|
ds.storage.translations.SetReadOnly(true)
|
|
} else {
|
|
return
|
|
}
|
|
if ds.storage.verses, err = root.Chroot(DATASTORE_VERSES); err == nil {
|
|
ds.storage.verses.SetReadOnly(true)
|
|
} else {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type storage struct {
|
|
chats vfs.MutableFS
|
|
translations vfs.VFS
|
|
root vfs.VFS
|
|
verses vfs.VFS
|
|
}
|