Documentation
¶
Overview ¶
Package store provides abstractions for file storage operations.
Index ¶
- type FileInfo
- type LocalStore
- func (s *LocalStore) BeginTx(_ context.Context) (Transaction, error)
- func (s *LocalStore) Exists(ctx context.Context, path string) (bool, error)
- func (s *LocalStore) FS() fs.FS
- func (s *LocalStore) IsRemoteEnabled() bool
- func (s *LocalStore) List(ctx context.Context, dir string) ([]FileInfo, error)
- func (s *LocalStore) Lock()
- func (s *LocalStore) Pull(ctx context.Context) error
- func (s *LocalStore) Push(ctx context.Context) error
- func (s *LocalStore) Read(ctx context.Context, path string) ([]byte, error)
- func (s *LocalStore) RemoteConfig() *RemoteConfig
- func (s *LocalStore) TestConnection(ctx context.Context) error
- func (s *LocalStore) Unlock()
- type LocalStoreOption
- type ReadFSProvider
- type RemoteConfig
- func (c *RemoteConfig) EffectiveStorageMode() StorageMode
- func (c *RemoteConfig) GetAuth() (transport.AuthMethod, error)
- func (c *RemoteConfig) GetCommitPeriod() time.Duration
- func (c *RemoteConfig) HasQueueBranch() bool
- func (c *RemoteConfig) IsCommitEnabled() bool
- func (c *RemoteConfig) IsEnabled() bool
- func (c *RemoteConfig) IsPushEnabled() bool
- func (c *RemoteConfig) IsSSH() bool
- func (c *RemoteConfig) TestConnection(ctx context.Context) error
- type SplitStore
- func (s *SplitStore) BeginTx(ctx context.Context) (Transaction, error)
- func (s *SplitStore) ContentStore() *LocalStore
- func (s *SplitStore) Exists(ctx context.Context, path string) (bool, error)
- func (s *SplitStore) IsRemoteEnabled() bool
- func (s *SplitStore) List(ctx context.Context, dir string) ([]FileInfo, error)
- func (s *SplitStore) Lock()
- func (s *SplitStore) Pull(ctx context.Context) error
- func (s *SplitStore) Push(ctx context.Context) error
- func (s *SplitStore) QueueStore() *LocalStore
- func (s *SplitStore) Read(ctx context.Context, path string) ([]byte, error)
- func (s *SplitStore) RemoteConfig() *RemoteConfig
- func (s *SplitStore) Unlock()
- type StorageMode
- type Store
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
LocalStore implements Store using local filesystem and git.
func NewLocalStore ¶
func NewLocalStore(path string, opts ...LocalStoreOption) (*LocalStore, error)
NewLocalStore creates a new local store at the given path.
func (*LocalStore) BeginTx ¶
func (s *LocalStore) BeginTx(_ context.Context) (Transaction, error)
BeginTx starts a new transaction.
func (*LocalStore) IsRemoteEnabled ¶
func (s *LocalStore) IsRemoteEnabled() bool
IsRemoteEnabled returns true if remote git operations are configured.
func (*LocalStore) Lock ¶
func (s *LocalStore) Lock()
Lock acquires the store's write lock for external coordination.
func (*LocalStore) Pull ¶
func (s *LocalStore) Pull(ctx context.Context) error
Pull fetches and merges changes from the remote repository.
func (*LocalStore) Push ¶
func (s *LocalStore) Push(ctx context.Context) error
Push pushes local commits to the remote repository. If a non-fast-forward error occurs, it will attempt to pull first and retry the push.
func (*LocalStore) RemoteConfig ¶
func (s *LocalStore) RemoteConfig() *RemoteConfig
RemoteConfig returns the remote configuration.
func (*LocalStore) TestConnection ¶
func (s *LocalStore) TestConnection(ctx context.Context) error
TestConnection tests the connection to the remote repository.
type LocalStoreOption ¶
type LocalStoreOption func(*LocalStore)
LocalStoreOption configures LocalStore.
func WithCreateBranchIfMissing ¶ added in v0.8.0
func WithCreateBranchIfMissing() LocalStoreOption
WithCreateBranchIfMissing makes the store initialize a fresh local branch (pushed lazily on first commit) when the configured branch does not yet exist on the remote, instead of failing to clone. Used for the queue branch.
func WithLogger ¶
func WithLogger(l *slog.Logger) LocalStoreOption
WithLogger sets a custom logger for the store.
func WithRemoteConfig ¶
func WithRemoteConfig(cfg *RemoteConfig) LocalStoreOption
WithRemoteConfig sets the remote git configuration.
type ReadFSProvider ¶
ReadFSProvider returns an fs.FS view for read-only consumers.
type RemoteConfig ¶
type RemoteConfig struct {
Storage StorageMode // Storage mode: "local", "remote", or auto-detect (NTN_STORAGE)
URL string // Remote git repository URL (NTN_GIT_URL)
Password string // Password/token for HTTPS auth (NTN_GIT_PASS)
Branch string // Target branch (NTN_GIT_BRANCH)
QueueBranch string // Separate branch for the queue (NTN_QUEUE_BRANCH), empty = disabled
User string // Commit author name (NTN_GIT_USER)
Email string // Commit author email (NTN_GIT_EMAIL)
Commit bool // Enable automatic git commit (NTN_COMMIT)
CommitPeriod time.Duration // Periodic commit interval during sync (NTN_COMMIT_PERIOD)
Push *bool // Push to remote after commits (NTN_PUSH), nil means auto-detect
}
RemoteConfig holds configuration for remote git operations.
func LoadRemoteConfigFromEnv ¶
func LoadRemoteConfigFromEnv() *RemoteConfig
LoadRemoteConfigFromEnv loads remote configuration from environment variables.
func (*RemoteConfig) EffectiveStorageMode ¶
func (c *RemoteConfig) EffectiveStorageMode() StorageMode
EffectiveStorageMode returns the effective storage mode after auto-detection. If Storage is set explicitly, it returns that value. Otherwise, it returns "remote" if URL is configured, or "local" if not.
func (*RemoteConfig) GetAuth ¶
func (c *RemoteConfig) GetAuth() (transport.AuthMethod, error)
GetAuth returns the appropriate authentication method for the remote URL.
func (*RemoteConfig) GetCommitPeriod ¶
func (c *RemoteConfig) GetCommitPeriod() time.Duration
GetCommitPeriod returns the periodic commit interval.
func (*RemoteConfig) HasQueueBranch ¶ added in v0.8.0
func (c *RemoteConfig) HasQueueBranch() bool
HasQueueBranch returns true if a separate queue branch is configured.
func (*RemoteConfig) IsCommitEnabled ¶
func (c *RemoteConfig) IsCommitEnabled() bool
IsCommitEnabled returns true if automatic commits are enabled.
func (*RemoteConfig) IsEnabled ¶
func (c *RemoteConfig) IsEnabled() bool
IsEnabled returns true if remote operations should be used. This checks both the storage mode and whether a URL is configured.
func (*RemoteConfig) IsPushEnabled ¶
func (c *RemoteConfig) IsPushEnabled() bool
IsPushEnabled returns true if push to remote is enabled. When NTN_PUSH is not explicitly set, defaults to true if NTN_GIT_URL is set.
func (*RemoteConfig) IsSSH ¶
func (c *RemoteConfig) IsSSH() bool
IsSSH returns true if the URL is an SSH URL.
func (*RemoteConfig) TestConnection ¶
func (c *RemoteConfig) TestConnection(ctx context.Context) error
TestConnection tests the connection to the remote repository.
type SplitStore ¶ added in v0.7.0
type SplitStore struct {
// contains filtered or unexported fields
}
SplitStore routes operations by path prefix. Paths under ".notion-sync/queue" go to queueStore (the queue branch), everything else — including content, ".notion-sync/ids", and ".notion-sync/state.json" — goes to contentStore (the main branch).
func NewSplitStore ¶ added in v0.7.0
func NewSplitStore(contentStore, queueStore *LocalStore) *SplitStore
NewSplitStore creates a new SplitStore that routes queue operations to a separate store.
func (*SplitStore) BeginTx ¶ added in v0.7.0
func (s *SplitStore) BeginTx(ctx context.Context) (Transaction, error)
BeginTx starts a split transaction that routes writes to the correct store.
func (*SplitStore) ContentStore ¶ added in v0.7.0
func (s *SplitStore) ContentStore() *LocalStore
ContentStore returns the underlying content store.
func (*SplitStore) Exists ¶ added in v0.7.0
Exists checks if a file exists in the appropriate store.
func (*SplitStore) IsRemoteEnabled ¶ added in v0.7.0
func (s *SplitStore) IsRemoteEnabled() bool
IsRemoteEnabled returns true if the content store has remote operations configured.
func (*SplitStore) Lock ¶ added in v0.7.0
func (s *SplitStore) Lock()
Lock acquires locks on both stores (content first).
func (*SplitStore) Pull ¶ added in v0.7.0
func (s *SplitStore) Pull(ctx context.Context) error
Pull fetches and merges changes from remote for both stores.
func (*SplitStore) Push ¶ added in v0.7.0
func (s *SplitStore) Push(ctx context.Context) error
Push pushes both stores to their respective remotes.
func (*SplitStore) QueueStore ¶ added in v0.8.0
func (s *SplitStore) QueueStore() *LocalStore
QueueStore returns the underlying queue store.
func (*SplitStore) RemoteConfig ¶ added in v0.7.0
func (s *SplitStore) RemoteConfig() *RemoteConfig
RemoteConfig returns the content store's remote configuration.
func (*SplitStore) Unlock ¶ added in v0.7.0
func (s *SplitStore) Unlock()
Unlock releases locks on both stores (queue first to avoid deadlock).
type StorageMode ¶
type StorageMode string
StorageMode defines the storage mode for git operations.
const ( // StorageModeAuto automatically detects the storage mode based on configuration. StorageModeAuto StorageMode = "" // StorageModeLocal uses local-only storage (no remote operations). StorageModeLocal StorageMode = "local" // StorageModeRemote uses remote storage (pull/push enabled). StorageModeRemote StorageMode = "remote" )
type Store ¶
type Store interface {
// Read operations
Read(ctx context.Context, path string) ([]byte, error)
Exists(ctx context.Context, path string) (bool, error)
List(ctx context.Context, dir string) ([]FileInfo, error)
// Transaction management - all writes go through transactions
BeginTx(ctx context.Context) (Transaction, error)
// Remote operations
Push(ctx context.Context) error
// Concurrency control for external coordination (e.g., sync worker)
Lock()
Unlock()
}
Store abstracts file storage with transactional write operations.
type Transaction ¶
type Transaction interface {
// Write operations - applied immediately to filesystem
Write(ctx context.Context, path string, content []byte) error
WriteStream(ctx context.Context, path string, reader io.Reader) (int64, error)
Delete(ctx context.Context, path string) error
Mkdir(ctx context.Context, path string) error
// Commit creates a git commit with all changes made in this transaction.
// After commit, the transaction can continue to be used for more changes.
Commit(ctx context.Context, message string) error
// Rollback reverts all uncommitted changes and closes the transaction.
Rollback(ctx context.Context) error
}
Transaction groups multiple write operations. All writes are applied immediately to the filesystem. Commit creates a git commit with all changes. Rollback reverts uncommitted changes.