Compare commits

..

No commits in common. "e7b88bcc09ae5046378ef0341f943227488d6b01" and "d6546e5ff979c56de3af36e8b55f0015528ccf82" have entirely different histories.

12 changed files with 8 additions and 157 deletions

View file

@ -13,7 +13,6 @@ tasks:
- '**/*.go'
cmds:
- go fmt ./...
- go mod tidy
vet:
desc: Vet go code

1
app.go
View file

@ -6,7 +6,6 @@ import (
"time"
"codeberg.org/danjones000/lenore/config"
_ "codeberg.org/danjones000/lenore/imports"
"codeberg.org/danjones000/lenore/store"
vocab "github.com/go-ap/activitypub"
"github.com/go-ap/client"

View file

@ -7,19 +7,14 @@ import (
"codeberg.org/danjones000/lenore"
"codeberg.org/danjones000/lenore/config"
"codeberg.org/danjones000/lenore/store"
"github.com/go-ap/storage-sqlite"
)
func main() {
conf := config.Config{
BaseURL: "http://localhost:4523/",
Conn: config.ConnSettings{
Store: "sqlite",
DSN: "storage",
},
}
conf := config.Config{BaseURL: "http://localhost:4523/"}
sqlConf := sqlite.Config{Path: "storage"}
db, err := store.MakeStore(conf.Conn.Store, conf)
db, err := sqlite.New(sqlConf)
if err != nil {
panic(err)
}

View file

@ -4,13 +4,6 @@ type Config struct {
Name string
Env Env
BaseURL string
Conn ConnSettings
}
type ConnSettings struct {
Store string
DSN string
AdditionalSettings map[string]any
}
func (c Config) Environment() Env {

4
go.mod
View file

@ -6,10 +6,8 @@ require (
github.com/go-ap/activitypub v0.0.0-20240910141749-b4b8c8aa484c
github.com/go-ap/client v0.0.0-20240910141951-13a4f3c4fd53
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/storage-sqlite v0.0.0-20240910151457-20fa80d963aa
github.com/openshift/osin v1.0.2-0.20220317075346-0f4d38c6e53f
github.com/stretchr/testify v1.9.0
)
@ -22,6 +20,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // 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/filters v0.0.0-20240910141936-c8f68cdf2bc9 // 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-fed/httpsig v1.1.0 // indirect
@ -32,6 +31,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.23 // 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/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect

3
imports/.gitignore vendored
View file

@ -1,3 +0,0 @@
*
!default.go
!.gitignore

View file

@ -1,5 +0,0 @@
package imports
import (
_ "codeberg.org/danjones000/lenore/store/sqlite"
)

View file

@ -1,17 +1,13 @@
package testmocks
import (
"codeberg.org/danjones000/lenore/config"
"codeberg.org/danjones000/lenore/store"
vocab "github.com/go-ap/activitypub"
"github.com/go-ap/filters"
)
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) {
i := vocab.ActorNew(iri, vocab.ActorType)
return i, nil
@ -40,6 +36,6 @@ func (s *st) RemoveFrom(col vocab.IRI, it vocab.Item) error {
func (s *st) Close() {
}
func GetStore() *st {
func GetStore() store.Store {
return &st{}
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -1,7 +1,6 @@
package store
import (
"codeberg.org/danjones000/lenore/config"
st "github.com/go-ap/fedbox/storage"
proc "github.com/go-ap/processing"
"github.com/openshift/osin"
@ -22,19 +21,7 @@ type ClientLister interface {
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 {
Bootstrapper
PartStore
}
type PartStore interface {
ClientSaver
ClientLister
proc.Store