- Add SQLite database connection management with proper error handling - Implement schema for files, chunks, blobs, and snapshots tables - Create repository pattern for each database table - Add transaction support with proper rollback handling - Integrate database module with fx dependency injection - Make index path configurable via VAULTIK_INDEX_PATH env var - Add fatal error handling for database integrity issues - Update DESIGN.md to clarify file_chunks vs chunk_files distinction - Remove FinalHash from BlobInfo (blobs are content-addressable) - Add file metadata support (mtime, ctime, mode, uid, gid, symlinks)
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.eeqj.de/sneak/vaultik/internal/config"
|
|
"git.eeqj.de/sneak/vaultik/internal/database"
|
|
"git.eeqj.de/sneak/vaultik/internal/globals"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// AppOptions contains common options for creating the fx application
|
|
type AppOptions struct {
|
|
ConfigPath string
|
|
Modules []fx.Option
|
|
Invokes []fx.Option
|
|
}
|
|
|
|
// NewApp creates a new fx application with common modules
|
|
func NewApp(opts AppOptions) *fx.App {
|
|
baseModules := []fx.Option{
|
|
fx.Supply(config.ConfigPath(opts.ConfigPath)),
|
|
fx.Provide(globals.New),
|
|
config.Module,
|
|
database.Module,
|
|
fx.NopLogger,
|
|
}
|
|
|
|
allOptions := append(baseModules, opts.Modules...)
|
|
allOptions = append(allOptions, opts.Invokes...)
|
|
|
|
return fx.New(allOptions...)
|
|
}
|
|
|
|
// RunApp starts and stops the fx application within the given context
|
|
func RunApp(ctx context.Context, app *fx.App) error {
|
|
if err := app.Start(ctx); err != nil {
|
|
return fmt.Errorf("failed to start app: %w", err)
|
|
}
|
|
defer func() {
|
|
if err := app.Stop(ctx); err != nil {
|
|
fmt.Printf("error stopping app: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
// Wait for context cancellation
|
|
<-ctx.Done()
|
|
return nil
|
|
}
|
|
|
|
// RunWithApp is a helper that creates and runs an fx app with the given options
|
|
func RunWithApp(ctx context.Context, opts AppOptions) error {
|
|
app := NewApp(opts)
|
|
return RunApp(ctx, app)
|
|
}
|