Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateGistChecksum(gist *models.GistResponse) (string, error)
- func CalculateSnippetChecksum(snippet *models.Snippet) (string, error)
- func DeriveEncryptionKeyWithSecret(salt, secret string) []byte
- func GenerateKey() ([]byte, error)
- func GetBackupFilename(format string, encrypted bool) string
- func GistToSnippet(gist *models.GistResponse, existingSnippet *models.Snippet) (*models.Snippet, error)
- func IsGistNotFound(err error) bool
- func SnippetToGistRequest(snippet *models.Snippet) (*models.GistRequest, error)
- func ValidateBackupFile(content []byte) (string, error)
- type BackupService
- type CleanupService
- type EncryptionService
- type GistNotFoundError
- type GistSyncService
- func (s *GistSyncService) DeleteGistForSnippet(ctx context.Context, snippetID string) error
- func (s *GistSyncService) DetectChanges(ctx context.Context, snippetID string) (models.SyncDirection, error)
- func (s *GistSyncService) DisableSyncForSnippet(ctx context.Context, snippetID string) error
- func (s *GistSyncService) EnableSyncForSnippet(ctx context.Context, snippetID string) error
- func (s *GistSyncService) ResolveConflict(ctx context.Context, conflictID int64, resolution string) error
- func (s *GistSyncService) SyncAll(ctx context.Context) (*models.SyncResult, error)
- func (s *GistSyncService) SyncGistToSnippet(ctx context.Context, gistID string) error
- func (s *GistSyncService) SyncSnippetToGist(ctx context.Context, snippetID string) error
- func (s *GistSyncService) VerifyMappings(ctx context.Context) (int, error)
- type GistSyncWorker
- type GitHubClient
- func (c *GitHubClient) CreateGist(ctx context.Context, req *models.GistRequest) (*models.GistResponse, error)
- func (c *GitHubClient) DeleteGist(ctx context.Context, gistID string) error
- func (c *GitHubClient) GetAuthenticatedUser(ctx context.Context) (string, error)
- func (c *GitHubClient) GetGist(ctx context.Context, gistID string) (*models.GistResponse, error)
- func (c *GitHubClient) ListGists(ctx context.Context) ([]*models.GistResponse, error)
- func (c *GitHubClient) UpdateGist(ctx context.Context, gistID string, req *models.GistRequest) (*models.GistResponse, error)
- type S3SyncService
- func (s *S3SyncService) DeleteBackup(ctx context.Context, key string) error
- func (s *S3SyncService) GetBackupURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (s *S3SyncService) ListBackups(ctx context.Context) ([]models.S3BackupInfo, error)
- func (s *S3SyncService) RestoreFromS3(ctx context.Context, key string, opts models.ImportOptions) (*models.S3RestoreResult, error)
- func (s *S3SyncService) SyncToS3(ctx context.Context, opts models.ExportOptions) (*models.S3SyncResult, error)
- type SnippetService
- func (s *SnippetService) Create(ctx context.Context, input *models.SnippetInput) (*models.Snippet, error)
- func (s *SnippetService) Delete(ctx context.Context, id string, permanent bool) error
- func (s *SnippetService) Duplicate(ctx context.Context, id string) (*models.Snippet, error)
- func (s *SnippetService) GetByID(ctx context.Context, id string) (*models.Snippet, error)
- func (s *SnippetService) GetByIDPublic(ctx context.Context, id string) (*models.Snippet, error)
- func (s *SnippetService) GetHistory(ctx context.Context, id string, limit int) ([]models.SnippetHistory, error)
- func (s *SnippetService) List(ctx context.Context, filter models.SnippetFilter) (*models.SnippetListResponse, error)
- func (s *SnippetService) Restore(ctx context.Context, id string) error
- func (s *SnippetService) RestoreFromHistory(ctx context.Context, snippetID string, historyID int64) (*models.Snippet, error)
- func (s *SnippetService) Search(ctx context.Context, query string, limit int) ([]models.Snippet, error)
- func (s *SnippetService) ToggleArchive(ctx context.Context, id string) (*models.Snippet, error)
- func (s *SnippetService) ToggleFavorite(ctx context.Context, id string) (*models.Snippet, error)
- func (s *SnippetService) Update(ctx context.Context, id string, input *models.SnippetInput) (*models.Snippet, error)
- func (s *SnippetService) WithFileRepo(fileRepo *repository.SnippetFileRepository) *SnippetService
- func (s *SnippetService) WithFolderRepo(folderRepo *repository.FolderRepository) *SnippetService
- func (s *SnippetService) WithHistoryRepo(historyRepo *repository.HistoryRepository) *SnippetService
- func (s *SnippetService) WithMaxFiles(max int) *SnippetService
- func (s *SnippetService) WithSettingsRepo(settingsRepo *repository.SettingsRepository) *SnippetService
- func (s *SnippetService) WithTagRepo(tagRepo *repository.TagRepository) *SnippetService
Constants ¶
const (
BackupVersion = "1.0"
)
Variables ¶
var ( ErrInvalidBackupFormat = errors.New("invalid backup format") ErrDecryptionFailed = errors.New("decryption failed - wrong password?") )
var ( ErrSnippetNotFound = errors.New("snippet not found") ErrValidation = errors.New("validation error") )
Common errors
Functions ¶
func CalculateGistChecksum ¶ added in v1.3.3
func CalculateGistChecksum(gist *models.GistResponse) (string, error)
CalculateGistChecksum calculates a checksum for a gist
func CalculateSnippetChecksum ¶ added in v1.3.3
CalculateSnippetChecksum calculates a checksum for a snippet
func DeriveEncryptionKeyWithSecret ¶ added in v1.5.0
DeriveEncryptionKeyWithSecret binds the persisted encryption salt to the session secret so a copied database plus salt file is not enough to decrypt stored third-party tokens.
func GenerateKey ¶ added in v1.3.3
GenerateKey generates a random 32-byte key for AES-256
func GetBackupFilename ¶
GetFilename generates a backup filename
func GistToSnippet ¶ added in v1.3.3
func GistToSnippet(gist *models.GistResponse, existingSnippet *models.Snippet) (*models.Snippet, error)
GistToSnippet converts a gist to a snippet
func IsGistNotFound ¶ added in v1.3.9
IsGistNotFound checks if an error is a GistNotFoundError
func SnippetToGistRequest ¶ added in v1.3.3
func SnippetToGistRequest(snippet *models.Snippet) (*models.GistRequest, error)
SnippetToGistRequest converts a snippet to a gist request
func ValidateBackupFile ¶
ValidateBackupFile checks if the content looks like a valid backup
Types ¶
type BackupService ¶
type BackupService struct {
// contains filtered or unexported fields
}
BackupService handles backup and restore operations
func NewBackupService ¶
func NewBackupService( db *sql.DB, snippetSvc *SnippetService, tagRepo *repository.TagRepository, folderRepo *repository.FolderRepository, fileRepo *repository.SnippetFileRepository, logger *slog.Logger, encryptionSalt string, ) *BackupService
NewBackupService creates a new backup service
func (*BackupService) Export ¶
func (b *BackupService) Export(ctx context.Context, opts models.ExportOptions) ([]byte, string, error)
Export creates a complete backup of all data
func (*BackupService) Import ¶
func (b *BackupService) Import(ctx context.Context, content []byte, opts models.ImportOptions) (*models.ImportResult, error)
Import restores data from a backup
type CleanupService ¶ added in v1.3.5
type CleanupService struct {
// contains filtered or unexported fields
}
CleanupService handles background cleanup tasks
func NewCleanupService ¶ added in v1.3.5
func NewCleanupService(snippetRepo *repository.SnippetRepository, logger *slog.Logger) *CleanupService
NewCleanupService creates a new cleanup service
func (*CleanupService) Start ¶ added in v1.3.5
func (s *CleanupService) Start(ctx context.Context)
Start starts the cleanup service periodic task
type EncryptionService ¶ added in v1.3.3
type EncryptionService struct {
// contains filtered or unexported fields
}
EncryptionService handles encryption and decryption of sensitive data
func NewEncryptionService ¶ added in v1.3.3
func NewEncryptionService(key []byte) (*EncryptionService, error)
NewEncryptionService creates a new encryption service key should be 32 bytes for AES-256
type GistNotFoundError ¶ added in v1.3.9
type GistNotFoundError struct {
GistID string
}
GistNotFoundError indicates a gist was not found (deleted or never existed)
func (*GistNotFoundError) Error ¶ added in v1.3.9
func (e *GistNotFoundError) Error() string
type GistSyncService ¶ added in v1.3.3
type GistSyncService struct {
// contains filtered or unexported fields
}
GistSyncService handles gist synchronization operations
func NewGistSyncService ¶ added in v1.3.3
func NewGistSyncService( githubClient *GitHubClient, snippetRepo *repository.SnippetRepository, fileRepo *repository.SnippetFileRepository, syncRepo *repository.GistSyncRepository, encryptionSvc *EncryptionService, ) *GistSyncService
NewGistSyncService creates a new gist sync service
func (*GistSyncService) DeleteGistForSnippet ¶ added in v1.7.5
func (s *GistSyncService) DeleteGistForSnippet(ctx context.Context, snippetID string) error
DeleteGistForSnippet deletes the gist on GitHub and removes the sync mapping
func (*GistSyncService) DetectChanges ¶ added in v1.3.3
func (s *GistSyncService) DetectChanges(ctx context.Context, snippetID string) (models.SyncDirection, error)
DetectChanges detects what changed between snippet and gist
func (*GistSyncService) DisableSyncForSnippet ¶ added in v1.3.3
func (s *GistSyncService) DisableSyncForSnippet(ctx context.Context, snippetID string) error
DisableSyncForSnippet disables sync for a snippet
func (*GistSyncService) EnableSyncForSnippet ¶ added in v1.3.3
func (s *GistSyncService) EnableSyncForSnippet(ctx context.Context, snippetID string) error
EnableSyncForSnippet enables sync for a snippet
func (*GistSyncService) ResolveConflict ¶ added in v1.3.3
func (s *GistSyncService) ResolveConflict(ctx context.Context, conflictID int64, resolution string) error
ResolveConflict resolves a conflict with the given strategy
func (*GistSyncService) SyncAll ¶ added in v1.3.3
func (s *GistSyncService) SyncAll(ctx context.Context) (*models.SyncResult, error)
SyncAll syncs all enabled mappings
func (*GistSyncService) SyncGistToSnippet ¶ added in v1.3.3
func (s *GistSyncService) SyncGistToSnippet(ctx context.Context, gistID string) error
SyncGistToSnippet syncs a gist to its corresponding snippet
func (*GistSyncService) SyncSnippetToGist ¶ added in v1.3.3
func (s *GistSyncService) SyncSnippetToGist(ctx context.Context, snippetID string) error
SyncSnippetToGist syncs a snippet to its corresponding gist
func (*GistSyncService) VerifyMappings ¶ added in v1.3.9
func (s *GistSyncService) VerifyMappings(ctx context.Context) (int, error)
VerifyMappings checks all mappings against GitHub and removes any whose gists have been deleted. Returns the number of removed mappings.
type GistSyncWorker ¶ added in v1.3.3
type GistSyncWorker struct {
// contains filtered or unexported fields
}
GistSyncWorker handles background synchronization
func NewGistSyncWorker ¶ added in v1.3.3
func NewGistSyncWorker( syncRepo *repository.GistSyncRepository, snippetRepo *repository.SnippetRepository, fileRepo *repository.SnippetFileRepository, encryptionSvc *EncryptionService, logger *slog.Logger, ) *GistSyncWorker
NewGistSyncWorker creates a new background sync worker
func (*GistSyncWorker) IsRunning ¶ added in v1.3.3
func (w *GistSyncWorker) IsRunning() bool
IsRunning returns whether the worker is currently running
func (*GistSyncWorker) Start ¶ added in v1.3.3
func (w *GistSyncWorker) Start(ctx context.Context) error
Start begins the background sync worker
func (*GistSyncWorker) Stop ¶ added in v1.3.3
func (w *GistSyncWorker) Stop() error
Stop gracefully stops the background sync worker
type GitHubClient ¶ added in v1.3.3
type GitHubClient struct {
// contains filtered or unexported fields
}
GitHubClient handles GitHub API operations
func NewGitHubClient ¶ added in v1.3.3
func NewGitHubClient(token string) *GitHubClient
NewGitHubClient creates a new GitHub API client
func (*GitHubClient) CreateGist ¶ added in v1.3.3
func (c *GitHubClient) CreateGist(ctx context.Context, req *models.GistRequest) (*models.GistResponse, error)
CreateGist creates a new gist
func (*GitHubClient) DeleteGist ¶ added in v1.3.3
func (c *GitHubClient) DeleteGist(ctx context.Context, gistID string) error
DeleteGist deletes a gist
func (*GitHubClient) GetAuthenticatedUser ¶ added in v1.3.3
func (c *GitHubClient) GetAuthenticatedUser(ctx context.Context) (string, error)
GetAuthenticatedUser retrieves the authenticated user's information
func (*GitHubClient) GetGist ¶ added in v1.3.3
func (c *GitHubClient) GetGist(ctx context.Context, gistID string) (*models.GistResponse, error)
GetGist retrieves a gist by ID
func (*GitHubClient) ListGists ¶ added in v1.3.3
func (c *GitHubClient) ListGists(ctx context.Context) ([]*models.GistResponse, error)
ListGists retrieves all gists for the authenticated user
func (*GitHubClient) UpdateGist ¶ added in v1.3.3
func (c *GitHubClient) UpdateGist(ctx context.Context, gistID string, req *models.GistRequest) (*models.GistResponse, error)
UpdateGist updates an existing gist
type S3SyncService ¶
type S3SyncService struct {
// contains filtered or unexported fields
}
S3SyncService handles S3 backup operations
func NewS3SyncService ¶
func NewS3SyncService(storage *storage.S3Storage, backupSvc *BackupService, logger *slog.Logger) *S3SyncService
NewS3SyncService creates a new S3 sync service
func (*S3SyncService) DeleteBackup ¶
func (s *S3SyncService) DeleteBackup(ctx context.Context, key string) error
DeleteBackup removes a backup from S3
func (*S3SyncService) GetBackupURL ¶
func (s *S3SyncService) GetBackupURL(ctx context.Context, key string, expiry time.Duration) (string, error)
GetBackupURL generates a presigned URL for downloading a backup
func (*S3SyncService) ListBackups ¶
func (s *S3SyncService) ListBackups(ctx context.Context) ([]models.S3BackupInfo, error)
ListBackups returns all backups stored in S3
func (*S3SyncService) RestoreFromS3 ¶
func (s *S3SyncService) RestoreFromS3(ctx context.Context, key string, opts models.ImportOptions) (*models.S3RestoreResult, error)
RestoreFromS3 downloads and restores a backup from S3
func (*S3SyncService) SyncToS3 ¶
func (s *S3SyncService) SyncToS3(ctx context.Context, opts models.ExportOptions) (*models.S3SyncResult, error)
SyncToS3 uploads a backup to S3
type SnippetService ¶
type SnippetService struct {
// contains filtered or unexported fields
}
SnippetService handles snippet business logic
func NewSnippetService ¶
func NewSnippetService(repo *repository.SnippetRepository, logger *slog.Logger) *SnippetService
NewSnippetService creates a new snippet service
func (*SnippetService) Create ¶
func (s *SnippetService) Create(ctx context.Context, input *models.SnippetInput) (*models.Snippet, error)
Create creates a new snippet
func (*SnippetService) GetByIDPublic ¶
GetByIDPublic retrieves a public snippet by ID and increments view count
func (*SnippetService) GetHistory ¶ added in v1.2.0
func (s *SnippetService) GetHistory(ctx context.Context, id string, limit int) ([]models.SnippetHistory, error)
GetHistory retrieves the modification history for a snippet
func (*SnippetService) List ¶
func (s *SnippetService) List(ctx context.Context, filter models.SnippetFilter) (*models.SnippetListResponse, error)
List retrieves snippets with filtering and pagination
func (*SnippetService) Restore ¶ added in v1.3.5
func (s *SnippetService) Restore(ctx context.Context, id string) error
Restore restores a soft-deleted snippet
func (*SnippetService) RestoreFromHistory ¶ added in v1.2.0
func (s *SnippetService) RestoreFromHistory(ctx context.Context, snippetID string, historyID int64) (*models.Snippet, error)
RestoreFromHistory restores a snippet from a specific history entry
func (*SnippetService) Search ¶
func (s *SnippetService) Search(ctx context.Context, query string, limit int) ([]models.Snippet, error)
Search performs full-text search on snippets
func (*SnippetService) ToggleArchive ¶ added in v1.2.0
ToggleArchive toggles the archive status of a snippet
func (*SnippetService) ToggleFavorite ¶
ToggleFavorite toggles the favorite status of a snippet
func (*SnippetService) Update ¶
func (s *SnippetService) Update(ctx context.Context, id string, input *models.SnippetInput) (*models.Snippet, error)
Update updates an existing snippet
func (*SnippetService) WithFileRepo ¶
func (s *SnippetService) WithFileRepo(fileRepo *repository.SnippetFileRepository) *SnippetService
WithFileRepo adds file repository to the service
func (*SnippetService) WithFolderRepo ¶
func (s *SnippetService) WithFolderRepo(folderRepo *repository.FolderRepository) *SnippetService
WithFolderRepo adds folder repository to the service
func (*SnippetService) WithHistoryRepo ¶ added in v1.2.0
func (s *SnippetService) WithHistoryRepo(historyRepo *repository.HistoryRepository) *SnippetService
WithHistoryRepo adds history repository to the service
func (*SnippetService) WithMaxFiles ¶
func (s *SnippetService) WithMaxFiles(max int) *SnippetService
WithMaxFiles sets the maximum files per snippet
func (*SnippetService) WithSettingsRepo ¶ added in v1.2.0
func (s *SnippetService) WithSettingsRepo(settingsRepo *repository.SettingsRepository) *SnippetService
WithSettingsRepo adds settings repository to the service
func (*SnippetService) WithTagRepo ¶
func (s *SnippetService) WithTagRepo(tagRepo *repository.TagRepository) *SnippetService
WithTagRepo adds tag repository to the service