feat: add blobstore to salty

This commit is contained in:
Jon Lundy
2023-01-28 10:35:46 -07:00
parent 0f504a98e9
commit 3f3ea4439c
9 changed files with 461 additions and 167 deletions

View File

@@ -5,6 +5,9 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"github.com/sour-is/ev"
"github.com/sour-is/ev/app/salty"
@@ -29,13 +32,28 @@ var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error
addr = ht.Addr
}
var opts []salty.Option
base, err := url.JoinPath(env.Default("SALTY_BASE_URL", "http://"+addr), "inbox")
if err != nil {
span.RecordError(err)
return err
}
opts = append(opts, salty.WithBaseURL(base))
salty, err := salty.New(ctx, eventstore, base)
if p := env.Default("SALTY_BLOB_DIR", ""); p != "" {
if strings.HasPrefix(p, "~/") {
home, _ := os.UserHomeDir()
p = filepath.Join(home, strings.TrimPrefix(p, "~/"))
}
opts = append(opts, salty.WithBlobStore(p))
}
salty, err := salty.New(
ctx,
eventstore,
opts...,
)
if err != nil {
span.RecordError(err)
return err

View File

@@ -21,12 +21,12 @@ func main() {
<-ctx.Done()
defer cancel() // restore interrupt function
}()
if err := Run(ctx); err != nil {
if err := run(ctx); err != nil {
log.Fatal(err)
os.Exit(1)
}
}
func Run(ctx context.Context) error {
func run(ctx context.Context) error {
svc := &service.Harness{}
ctx, stop := lg.Init(ctx, appName)
svc.OnStop(stop)

View File

@@ -12,6 +12,7 @@ import (
"github.com/matryer/is"
"github.com/sour-is/ev/app/webfinger"
"github.com/sour-is/ev/pkg/service"
"golang.org/x/sync/errgroup"
)
@@ -29,15 +30,26 @@ func TestMain(m *testing.M) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
running := make(chan struct{})
apps.Register(99, func(ctx context.Context, s *service.Harness) error {
go func() {
<-s.OnRunning()
close(running)
}()
return nil
})
wg, ctx := errgroup.WithContext(ctx)
wg.Go(func() error {
// Run application
if err := Run(ctx); err != nil {
if err := run(ctx); err != nil {
return err
}
return nil
})
wg.Go(func() error {
<-running
m.Run()
cancel()
return nil