Compare commits
No commits in common. "e7b88bcc09ae5046378ef0341f943227488d6b01" and "d6546e5ff979c56de3af36e8b55f0015528ccf82" have entirely different histories.
e7b88bcc09
...
d6546e5ff9
12 changed files with 8 additions and 157 deletions
|
|
@ -13,7 +13,6 @@ tasks:
|
||||||
- '**/*.go'
|
- '**/*.go'
|
||||||
cmds:
|
cmds:
|
||||||
- go fmt ./...
|
- go fmt ./...
|
||||||
- go mod tidy
|
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
desc: Vet go code
|
desc: Vet go code
|
||||||
|
|
|
||||||
1
app.go
1
app.go
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeberg.org/danjones000/lenore/config"
|
"codeberg.org/danjones000/lenore/config"
|
||||||
_ "codeberg.org/danjones000/lenore/imports"
|
|
||||||
"codeberg.org/danjones000/lenore/store"
|
"codeberg.org/danjones000/lenore/store"
|
||||||
vocab "github.com/go-ap/activitypub"
|
vocab "github.com/go-ap/activitypub"
|
||||||
"github.com/go-ap/client"
|
"github.com/go-ap/client"
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,14 @@ import (
|
||||||
|
|
||||||
"codeberg.org/danjones000/lenore"
|
"codeberg.org/danjones000/lenore"
|
||||||
"codeberg.org/danjones000/lenore/config"
|
"codeberg.org/danjones000/lenore/config"
|
||||||
"codeberg.org/danjones000/lenore/store"
|
"github.com/go-ap/storage-sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
conf := config.Config{
|
conf := config.Config{BaseURL: "http://localhost:4523/"}
|
||||||
BaseURL: "http://localhost:4523/",
|
sqlConf := sqlite.Config{Path: "storage"}
|
||||||
Conn: config.ConnSettings{
|
|
||||||
Store: "sqlite",
|
|
||||||
DSN: "storage",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := store.MakeStore(conf.Conn.Store, conf)
|
db, err := sqlite.New(sqlConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,6 @@ type Config struct {
|
||||||
Name string
|
Name string
|
||||||
Env Env
|
Env Env
|
||||||
BaseURL string
|
BaseURL string
|
||||||
Conn ConnSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConnSettings struct {
|
|
||||||
Store string
|
|
||||||
DSN string
|
|
||||||
AdditionalSettings map[string]any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) Environment() Env {
|
func (c Config) Environment() Env {
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -6,10 +6,8 @@ require (
|
||||||
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
|
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
|
||||||
github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53
|
github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53
|
||||||
github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399
|
github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399
|
||||||
github.com/go-ap/filters v0.0.0-20240910141936-c8f68cdf2bc9
|
|
||||||
github.com/go-ap/processing v0.0.0-20240910151355-8284a5ce9c22
|
github.com/go-ap/processing v0.0.0-20240910151355-8284a5ce9c22
|
||||||
github.com/go-ap/storage-sqlite v0.0.0-20240910151457-20fa80d963aa
|
github.com/go-ap/storage-sqlite v0.0.0-20240910151457-20fa80d963aa
|
||||||
github.com/openshift/osin v1.0.2-0.20220317075346-0f4d38c6e53f
|
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -22,6 +20,7 @@ require (
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/go-ap/cache v0.0.0-20240910141827-94f8ac1a9133 // indirect
|
github.com/go-ap/cache v0.0.0-20240910141827-94f8ac1a9133 // indirect
|
||||||
github.com/go-ap/errors v0.0.0-20240910140019-1e9d33cc1568 // indirect
|
github.com/go-ap/errors v0.0.0-20240910140019-1e9d33cc1568 // indirect
|
||||||
|
github.com/go-ap/filters v0.0.0-20240910141936-c8f68cdf2bc9 // indirect
|
||||||
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73 // indirect
|
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73 // indirect
|
||||||
github.com/go-chi/chi/v5 v5.1.0 // indirect
|
github.com/go-chi/chi/v5 v5.1.0 // indirect
|
||||||
github.com/go-fed/httpsig v1.1.0 // indirect
|
github.com/go-fed/httpsig v1.1.0 // indirect
|
||||||
|
|
@ -32,6 +31,7 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.23 // indirect
|
github.com/mattn/go-sqlite3 v1.14.23 // indirect
|
||||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||||
|
github.com/openshift/osin v1.0.2-0.20220317075346-0f4d38c6e53f // indirect
|
||||||
github.com/pborman/uuid v1.2.1 // indirect
|
github.com/pborman/uuid v1.2.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
|
|
|
||||||
3
imports/.gitignore
vendored
3
imports/.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
*
|
|
||||||
!default.go
|
|
||||||
!.gitignore
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package imports
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "codeberg.org/danjones000/lenore/store/sqlite"
|
|
||||||
)
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
package testmocks
|
package testmocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"codeberg.org/danjones000/lenore/config"
|
"codeberg.org/danjones000/lenore/store"
|
||||||
vocab "github.com/go-ap/activitypub"
|
vocab "github.com/go-ap/activitypub"
|
||||||
"github.com/go-ap/filters"
|
"github.com/go-ap/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
type st struct{}
|
type st struct{}
|
||||||
|
|
||||||
func (s *st) Bootstrap(config.Config) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *st) Load(iri vocab.IRI, filters ...filters.Check) (vocab.Item, error) {
|
func (s *st) Load(iri vocab.IRI, filters ...filters.Check) (vocab.Item, error) {
|
||||||
i := vocab.ActorNew(iri, vocab.ActorType)
|
i := vocab.ActorNew(iri, vocab.ActorType)
|
||||||
return i, nil
|
return i, nil
|
||||||
|
|
@ -40,6 +36,6 @@ func (s *st) RemoveFrom(col vocab.IRI, it vocab.Item) error {
|
||||||
func (s *st) Close() {
|
func (s *st) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStore() *st {
|
func GetStore() store.Store {
|
||||||
return &st{}
|
return &st{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package store
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"codeberg.org/danjones000/lenore/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrNoFactory = errors.New("unknown factory")
|
|
||||||
|
|
||||||
type StoreFactory func(config.Config) (Store, error)
|
|
||||||
|
|
||||||
var factories map[string]StoreFactory
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
factories = make(map[string]StoreFactory)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddFactory(name string, f StoreFactory) {
|
|
||||||
factories[name] = f
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetFactory(name string) StoreFactory {
|
|
||||||
return factories[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeStore(name string, conf config.Config) (Store, error) {
|
|
||||||
f, ok := factories[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)
|
|
||||||
}
|
|
||||||
return f(conf)
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
package store
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"codeberg.org/danjones000/lenore/config"
|
|
||||||
"codeberg.org/danjones000/lenore/internal/testmocks"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
var f StoreFactory = func(config.Config) (Store, error) {
|
|
||||||
return testmocks.GetStore(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAddFactory(t *testing.T) {
|
|
||||||
AddFactory("mock", f)
|
|
||||||
defer delete(factories, "mock")
|
|
||||||
_, ok := factories["mock"]
|
|
||||||
assert.True(t, ok)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetFactoryNil(t *testing.T) {
|
|
||||||
f := GetFactory("mock")
|
|
||||||
assert.Nil(t, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetFactoryNotNil(t *testing.T) {
|
|
||||||
AddFactory("mock", f)
|
|
||||||
defer delete(factories, "mock")
|
|
||||||
f := GetFactory("mock")
|
|
||||||
assert.NotNil(t, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeStoreError(t *testing.T) {
|
|
||||||
s, e := MakeStore("mock", config.Config{})
|
|
||||||
assert.Nil(t, s)
|
|
||||||
assert.ErrorIs(t, e, ErrNoFactory)
|
|
||||||
assert.ErrorContains(t, e, ErrNoFactory.Error()+": mock")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeStoreNoError(t *testing.T) {
|
|
||||||
AddFactory("mock", f)
|
|
||||||
defer delete(factories, "mock")
|
|
||||||
s, e := MakeStore("mock", config.Config{})
|
|
||||||
assert.NotNil(t, s)
|
|
||||||
assert.NoError(t, e)
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package sqlite
|
|
||||||
|
|
||||||
import (
|
|
||||||
"codeberg.org/danjones000/lenore/config"
|
|
||||||
"codeberg.org/danjones000/lenore/store"
|
|
||||||
"github.com/go-ap/storage-sqlite"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
store.AddFactory("sqlite", MakeStore)
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeStore(conf config.Config) (store.Store, error) {
|
|
||||||
sqlConf := sqlite.Config{Path: conf.Conn.DSN}
|
|
||||||
db, err := sqlite.New(sqlConf)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return Repo{db}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Repo struct {
|
|
||||||
store.PartStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Repo) Bootstrap(config.Config) error {
|
|
||||||
// @todo
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"codeberg.org/danjones000/lenore/config"
|
|
||||||
st "github.com/go-ap/fedbox/storage"
|
st "github.com/go-ap/fedbox/storage"
|
||||||
proc "github.com/go-ap/processing"
|
proc "github.com/go-ap/processing"
|
||||||
"github.com/openshift/osin"
|
"github.com/openshift/osin"
|
||||||
|
|
@ -22,19 +21,7 @@ type ClientLister interface {
|
||||||
GetClient(id string) (osin.Client, error)
|
GetClient(id string) (osin.Client, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bootstrapper interface {
|
|
||||||
// Bootstrap should initialize the data store so that it can be used.
|
|
||||||
// This will be called every time the application starts, so it MUST be idempotent and doesn't delete existing data.
|
|
||||||
// An option is to run migrations in this method.
|
|
||||||
Bootstrap(config.Config) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
Bootstrapper
|
|
||||||
PartStore
|
|
||||||
}
|
|
||||||
|
|
||||||
type PartStore interface {
|
|
||||||
ClientSaver
|
ClientSaver
|
||||||
ClientLister
|
ClientLister
|
||||||
proc.Store
|
proc.Store
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue