Documentation
¶
Overview ¶
Package source provides abstractions for reading files from various data sources. It defines a unified interface that supports local filesystem, Git repositories, and potentially other sources like S3 or GitLab in the future.
Index ¶
- Variables
- func RepoPathFromURL(repoURL string) (string, error)
- func VerifyGitInstalled() error
- func VerifyRepository(ctx context.Context, repoURL string, creds *GitCredentials) error
- type GitCredentials
- type GitOptions
- type GitSource
- func (s *GitSource) Branch() string
- func (s *GitSource) Close() error
- func (s *GitSource) CommitSHA() string
- func (s *GitSource) CommittedAt() time.Time
- func (s *GitSource) Open(ctx context.Context, path string) (io.ReadCloser, error)
- func (s *GitSource) Root() string
- func (s *GitSource) Stat(ctx context.Context, path string) (fs.FileInfo, error)
- type LocalSource
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPath indicates the provided path is invalid or inaccessible. ErrInvalidPath = errors.New("source: invalid path") // ErrGitCloneFailed indicates a git clone operation failed. ErrGitCloneFailed = errors.New("source: git clone failed") // ErrRepositoryNotFound indicates the repository does not exist or is inaccessible. ErrRepositoryNotFound = errors.New("source: repository not found") )
Sentinel errors for source operations.
Functions ¶
func RepoPathFromURL ¶
RepoPathFromURL extracts a filesystem-safe path from a repository URL. Example: "https://github.com/owner/repo.git" -> "github.com/owner/repo" Credentials in the URL are stripped and not included in error messages.
func VerifyGitInstalled ¶
func VerifyGitInstalled() error
VerifyGitInstalled checks if git is available in the system PATH.
func VerifyRepository ¶
func VerifyRepository(ctx context.Context, repoURL string, creds *GitCredentials) error
VerifyRepository checks if a repository exists and is accessible. It uses git ls-remote which doesn't count against API rate limits.
Types ¶
type GitCredentials ¶
GitCredentials contains authentication information for Git operations.
type GitOptions ¶
type GitOptions struct {
Branch string
Depth int
Credentials *GitCredentials
}
GitOptions configures how a Git repository is cloned.
type GitSource ¶
type GitSource struct {
// contains filtered or unexported fields
}
GitSource implements Source for Git repository access. It clones the repository to a temporary directory and provides filesystem-like access to its contents.
func NewGitSource ¶
NewGitSource clones a Git repository and returns a Source for accessing its files. The repository is cloned to a temporary directory with shallow clone (depth 1) by default. The caller must call Close() to clean up the cloned repository.
func (*GitSource) Close ¶
Close removes the cloned repository and releases resources. Close is idempotent; calling it multiple times has no additional effect.
func (*GitSource) CommittedAt ¶ added in v1.5.0
CommittedAt returns the commit timestamp of the HEAD commit.
type LocalSource ¶
type LocalSource struct {
// contains filtered or unexported fields
}
LocalSource implements Source for local filesystem access.
func NewLocalSource ¶
func NewLocalSource(rootPath string) (*LocalSource, error)
NewLocalSource creates a new LocalSource for the given root path. The path must be an existing directory. Relative paths are converted to absolute paths.
func (*LocalSource) Close ¶
func (s *LocalSource) Close() error
Close is a no-op for LocalSource as there are no resources to release.
func (*LocalSource) Open ¶
func (s *LocalSource) Open(_ context.Context, path string) (io.ReadCloser, error)
Open opens the file at the given path for reading. The path must be relative to the source root. Paths attempting to escape the root directory will return ErrInvalidPath.
func (*LocalSource) Root ¶
func (s *LocalSource) Root() string
Root returns the absolute path to the source root directory.
type Source ¶
type Source interface {
// Root returns the root path of the source.
// For LocalSource, this is the absolute path to the directory.
// For GitSource, this is the path to the cloned repository.
Root() string
// Open opens the file at the given path for reading.
// The path should be relative to the source root.
// Callers must close the returned ReadCloser when done.
Open(ctx context.Context, path string) (io.ReadCloser, error)
// Stat returns file info for the given path.
// The path should be relative to the source root.
Stat(ctx context.Context, path string) (fs.FileInfo, error)
// Close releases any resources held by the source.
// For GitSource, this removes the cloned repository.
// Close is idempotent; calling it multiple times has no effect.
Close() error
}
Source defines the interface for reading files from a data source. Implementations must be safe for concurrent use.