52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
|
package registry
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
|
||
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||
|
"forge.cadoles.com/arcad/edge/pkg/storage/registry"
|
||
|
"forge.cadoles.com/arcad/edge/pkg/storage/sqlite"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
registry.AddDocumentStoreFactory("sqlite", documentStoreFactory)
|
||
|
registry.AddBlobStoreFactory("sqlite", blobStoreFactory)
|
||
|
}
|
||
|
|
||
|
func documentStoreFactory(url *url.URL) (storage.DocumentStore, error) {
|
||
|
dir := filepath.Dir(url.Host + url.Path)
|
||
|
|
||
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
path := url.Host + url.Path + "?" + url.RawQuery
|
||
|
|
||
|
db, err := sqlite.Open(path)
|
||
|
if err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
return sqlite.NewDocumentStoreWithDB(db), nil
|
||
|
}
|
||
|
|
||
|
func blobStoreFactory(url *url.URL) (storage.BlobStore, error) {
|
||
|
dir := filepath.Dir(url.Host + url.Path)
|
||
|
|
||
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
path := url.Host + url.Path + "?" + url.RawQuery
|
||
|
|
||
|
db, err := sqlite.Open(path)
|
||
|
if err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
return sqlite.NewBlobStoreWithDB(db), nil
|
||
|
}
|