-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separates creation of NATS streams into a separate dedicated command. Signed-off-by: Brian McGee <[email protected]>
- Loading branch information
1 parent
f6832b8
commit 7ebff40
Showing
13 changed files
with
130 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package store | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/brianmcgee/nvix/pkg/blob" | ||
"github.com/brianmcgee/nvix/pkg/cli" | ||
"github.com/brianmcgee/nvix/pkg/directory" | ||
"github.com/brianmcgee/nvix/pkg/pathinfo" | ||
"github.com/charmbracelet/log" | ||
) | ||
|
||
type Init struct { | ||
Log cli.LogOptions `embed:""` | ||
Nats cli.NatsOptions `embed:""` | ||
} | ||
|
||
func (i *Init) Run() error { | ||
i.Log.ConfigureLogger() | ||
conn := i.Nats.Connect() | ||
|
||
ctx := context.Background() | ||
|
||
log.Info("initialising stores") | ||
|
||
log.Info("initialising blob chunk store") | ||
if err := blob.NewChunkStore(conn).Init(ctx); err != nil { | ||
log.Errorf("failed to initialise blob chunk store: %v", err) | ||
return err | ||
} | ||
|
||
log.Info("initialising blob meta store") | ||
if err := blob.NewMetaStore(conn).Init(ctx); err != nil { | ||
log.Errorf("failed to initialise blob meta store: %v", err) | ||
return err | ||
} | ||
|
||
log.Info("initialising directory store") | ||
if err := directory.NewDirectoryStore(conn).Init(ctx); err != nil { | ||
log.Errorf("failed to initialise directory store: %v", err) | ||
return err | ||
} | ||
|
||
log.Info("initialising path info store") | ||
if err := pathinfo.NewPathInfoStore(conn).Init(ctx); err != nil { | ||
log.Errorf("failed to initialise path info store: %v", err) | ||
return err | ||
} | ||
|
||
log.Info("initialising path info out idx store") | ||
if err := pathinfo.NewPathInfoOutIdxStore(conn).Init(ctx); err != nil { | ||
log.Errorf("failed to initialise path info out idx store: %v", err) | ||
return err | ||
} | ||
|
||
log.Info("initialising stores complete") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package store | ||
|
||
type Cli struct { | ||
Run Run `cmd:"" default:""` | ||
Run Run `cmd:"" default:""` | ||
Init Init `cmd:""` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/charmbracelet/log" | ||
"github.com/nats-io/nats.go" | ||
) | ||
|
||
type NatsOptions struct { | ||
NatsUrl string `short:"n" env:"NVIX_STORE_NATS_URL" default:"nats://localhost:4222"` | ||
NatsCredentials string `short:"c" env:"NVIX_STORE_NATS_CREDENTIALS_FILE" required:"" type:"path"` | ||
} | ||
|
||
func (no *NatsOptions) Connect() *nats.Conn { | ||
conn, err := nats.Connect(no.NatsUrl, nats.UserCredentials(no.NatsCredentials)) | ||
if err != nil { | ||
log.Fatalf("failed to connect to nats: %v", err) | ||
} | ||
return conn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters