adapters

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package adapters provides interfaces and implementations for external dependencies.

Package adapters provides concrete implementations of infrastructure ports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseLogLevel

func ParseLogLevel(level string) slog.Level

ParseLogLevel converts a string log level to slog.Level.

func WrapDirEntry

func WrapDirEntry(entry fs.DirEntry) domain.DirEntry

WrapDirEntry wraps a standard fs.DirEntry.

func WrapFileInfo

func WrapFileInfo(info fs.FileInfo) domain.FileInfo

WrapFileInfo wraps a standard fs.FileInfo.

Types

type AuthMethod

type AuthMethod interface {
	// contains filtered or unexported methods
}

AuthMethod represents a git authentication method.

This is a sealed interface implemented only by:

  • NoAuth
  • TokenAuth
  • SSHAuth

func ResolveAuth

func ResolveAuth(ctx context.Context, repoURL string) (AuthMethod, error)

ResolveAuth determines the appropriate authentication method for a repository URL.

Resolution priority:

  1. GITHUB_TOKEN environment variable → TokenAuth
  2. GIT_TOKEN environment variable → TokenAuth
  3. SSH keys in ~/.ssh/ → SSHAuth (for SSH URLs)
  4. GitHub CLI (gh) authenticated token → TokenAuth (for HTTPS GitHub URLs)
  5. NoAuth (public repositories)

The function inspects the URL to determine authentication needs. For SSH URLs (git@... or ssh://...), SSH key auth is preferred. For GitHub HTTPS URLs, checks gh CLI if environment tokens not set. This ensures SSH URLs use SSH keys as users expect.

type CloneOptions

type CloneOptions struct {
	// Auth specifies the authentication method.
	// If nil, no authentication is used (public repos only).
	Auth AuthMethod

	// Branch specifies which branch to clone.
	// If empty, the default branch is cloned.
	Branch string

	// Depth specifies how many commits to fetch.
	// If 0, full history is cloned.
	// If 1, only the latest commit is fetched (shallow clone).
	Depth int

	// Progress is an optional writer for clone progress output.
	// If nil, no progress is reported.
	Progress io.Writer
}

CloneOptions configures repository cloning behavior.

type GitCloner

type GitCloner interface {
	// Clone clones a repository from the specified URL to the target path.
	//
	// Returns an error if:
	//   - URL is invalid
	//   - Target path already exists
	//   - Authentication fails
	//   - Network errors occur
	//   - Repository is not accessible
	Clone(ctx context.Context, url string, path string, opts CloneOptions) error
}

GitCloner defines the interface for cloning git repositories.

type GoGitCloner

type GoGitCloner struct{}

GoGitCloner implements GitCloner using go-git library.

func NewGoGitCloner

func NewGoGitCloner() *GoGitCloner

NewGoGitCloner creates a new go-git based cloner.

func (*GoGitCloner) Clone

func (g *GoGitCloner) Clone(ctx context.Context, url string, path string, opts CloneOptions) error

Clone clones a git repository using go-git.

type MemFS

type MemFS struct {
	// contains filtered or unexported fields
}

MemFS implements an in-memory filesystem for testing. It is not thread-safe and should only be used in tests.

func NewMemFS

func NewMemFS() *MemFS

NewMemFS creates a new in-memory filesystem.

func (*MemFS) Exists

func (f *MemFS) Exists(ctx context.Context, name string) bool

func (*MemFS) IsDir

func (f *MemFS) IsDir(ctx context.Context, name string) (bool, error)
func (f *MemFS) IsSymlink(ctx context.Context, name string) (bool, error)

func (*MemFS) Lstat

func (f *MemFS) Lstat(ctx context.Context, name string) (domain.FileInfo, error)

func (*MemFS) Mkdir

func (f *MemFS) Mkdir(ctx context.Context, name string, perm fs.FileMode) error

func (*MemFS) MkdirAll

func (f *MemFS) MkdirAll(ctx context.Context, name string, perm fs.FileMode) error

func (*MemFS) ReadDir

func (f *MemFS) ReadDir(ctx context.Context, name string) ([]domain.DirEntry, error)

func (*MemFS) ReadFile

func (f *MemFS) ReadFile(ctx context.Context, name string) ([]byte, error)
func (f *MemFS) ReadLink(ctx context.Context, name string) (string, error)

func (*MemFS) Remove

func (f *MemFS) Remove(ctx context.Context, name string) error

func (*MemFS) RemoveAll

func (f *MemFS) RemoveAll(ctx context.Context, name string) error

func (*MemFS) Rename

func (f *MemFS) Rename(ctx context.Context, oldname, newname string) error

func (*MemFS) Stat

func (f *MemFS) Stat(ctx context.Context, name string) (domain.FileInfo, error)
func (f *MemFS) Symlink(ctx context.Context, oldname, newname string) error

func (*MemFS) WriteFile

func (f *MemFS) WriteFile(ctx context.Context, name string, data []byte, perm fs.FileMode) error

type NoAuth

type NoAuth struct{}

NoAuth represents no authentication (public repositories).

type NoopCounter

type NoopCounter struct{}

NoopCounter is a counter that does nothing.

func (*NoopCounter) Add

func (c *NoopCounter) Add(delta float64, labels ...string)

func (*NoopCounter) Inc

func (c *NoopCounter) Inc(labels ...string)

type NoopGauge

type NoopGauge struct{}

NoopGauge is a gauge that does nothing.

func (*NoopGauge) Dec

func (g *NoopGauge) Dec(labels ...string)

func (*NoopGauge) Inc

func (g *NoopGauge) Inc(labels ...string)

func (*NoopGauge) Set

func (g *NoopGauge) Set(value float64, labels ...string)

type NoopHistogram

type NoopHistogram struct{}

NoopHistogram is a histogram that does nothing.

func (*NoopHistogram) Observe

func (h *NoopHistogram) Observe(value float64, labels ...string)

type NoopLogger

type NoopLogger struct{}

NoopLogger is a logger that does nothing. Useful for testing and when logging is disabled.

func NewNoopLogger

func NewNoopLogger() *NoopLogger

NewNoopLogger creates a new no-op logger.

func (*NoopLogger) Debug

func (l *NoopLogger) Debug(ctx context.Context, msg string, args ...any)

func (*NoopLogger) Error

func (l *NoopLogger) Error(ctx context.Context, msg string, args ...any)

func (*NoopLogger) Info

func (l *NoopLogger) Info(ctx context.Context, msg string, args ...any)

func (*NoopLogger) Warn

func (l *NoopLogger) Warn(ctx context.Context, msg string, args ...any)

func (*NoopLogger) With

func (l *NoopLogger) With(args ...any) domain.Logger

type NoopMetrics

type NoopMetrics struct{}

NoopMetrics is a metrics collector that does nothing. Useful for testing and when metrics are disabled.

func NewNoopMetrics

func NewNoopMetrics() *NoopMetrics

NewNoopMetrics creates a new no-op metrics collector.

func (*NoopMetrics) Counter

func (m *NoopMetrics) Counter(name string, labels ...string) domain.Counter

func (*NoopMetrics) Gauge

func (m *NoopMetrics) Gauge(name string, labels ...string) domain.Gauge

func (*NoopMetrics) Histogram

func (m *NoopMetrics) Histogram(name string, labels ...string) domain.Histogram

type NoopSpan

type NoopSpan struct{}

NoopSpan is a span that does nothing.

func (*NoopSpan) End

func (s *NoopSpan) End()

func (*NoopSpan) RecordError

func (s *NoopSpan) RecordError(err error)

func (*NoopSpan) SetAttributes

func (s *NoopSpan) SetAttributes(attrs ...domain.Attribute)

type NoopTracer

type NoopTracer struct{}

NoopTracer is a tracer that does nothing. Useful for testing and when tracing is disabled.

func NewNoopTracer

func NewNoopTracer() *NoopTracer

NewNoopTracer creates a new no-op tracer.

func (*NoopTracer) Start

func (t *NoopTracer) Start(ctx context.Context, name string, opts ...domain.SpanOption) (context.Context, domain.Span)

type OSFilesystem

type OSFilesystem struct{}

OSFilesystem implements the FS interface using the os package.

func NewOSFilesystem

func NewOSFilesystem() *OSFilesystem

NewOSFilesystem creates a new OS filesystem adapter.

func (*OSFilesystem) Exists

func (f *OSFilesystem) Exists(ctx context.Context, name string) bool

Exists checks if a path exists.

func (*OSFilesystem) IsDir

func (f *OSFilesystem) IsDir(ctx context.Context, name string) (bool, error)

IsDir checks if a path is a directory.

func (f *OSFilesystem) IsSymlink(ctx context.Context, name string) (bool, error)

IsSymlink checks if a path is a symbolic link.

func (*OSFilesystem) Lstat

func (f *OSFilesystem) Lstat(ctx context.Context, name string) (domain.FileInfo, error)

Lstat returns file information without following symlinks.

func (*OSFilesystem) Mkdir

func (f *OSFilesystem) Mkdir(ctx context.Context, name string, perm fs.FileMode) error

Mkdir creates a directory.

func (*OSFilesystem) MkdirAll

func (f *OSFilesystem) MkdirAll(ctx context.Context, name string, perm fs.FileMode) error

MkdirAll creates a directory tree.

func (*OSFilesystem) ReadDir

func (f *OSFilesystem) ReadDir(ctx context.Context, name string) ([]domain.DirEntry, error)

ReadDir lists directory contents.

func (*OSFilesystem) ReadFile

func (f *OSFilesystem) ReadFile(ctx context.Context, name string) ([]byte, error)

ReadFile reads the entire file.

func (f *OSFilesystem) ReadLink(ctx context.Context, name string) (string, error)

ReadLink reads the target of a symbolic link.

func (*OSFilesystem) Remove

func (f *OSFilesystem) Remove(ctx context.Context, name string) error

Remove removes a file or empty directory.

func (*OSFilesystem) RemoveAll

func (f *OSFilesystem) RemoveAll(ctx context.Context, name string) error

RemoveAll removes a directory tree.

func (*OSFilesystem) Rename

func (f *OSFilesystem) Rename(ctx context.Context, oldname, newname string) error

Rename moves or renames a file.

func (*OSFilesystem) Stat

func (f *OSFilesystem) Stat(ctx context.Context, name string) (domain.FileInfo, error)

Stat returns file information.

func (f *OSFilesystem) Symlink(ctx context.Context, oldname, newname string) error

Symlink creates a symbolic link.

func (*OSFilesystem) WriteFile

func (f *OSFilesystem) WriteFile(ctx context.Context, name string, data []byte, perm fs.FileMode) error

WriteFile writes data to a file.

type SSHAuth

type SSHAuth struct {
	// PrivateKeyPath is the filesystem path to the SSH private key.
	PrivateKeyPath string

	// Password is an optional passphrase for encrypted keys.
	Password string
}

SSHAuth represents SSH key-based authentication.

type SlogLogger

type SlogLogger struct {
	// contains filtered or unexported fields
}

SlogLogger implements the Logger interface using log/slog.

func NewConsoleLogger

func NewConsoleLogger(w io.Writer, level string) *SlogLogger

NewConsoleLogger creates a logger with console-slog for human-readable output.

func NewSlogLogger

func NewSlogLogger(logger *slog.Logger) *SlogLogger

NewSlogLogger creates a new slog logger adapter.

func (*SlogLogger) Debug

func (l *SlogLogger) Debug(ctx context.Context, msg string, args ...any)

Debug logs a debug-level message.

func (*SlogLogger) Error

func (l *SlogLogger) Error(ctx context.Context, msg string, args ...any)

Error logs an error-level message.

func (*SlogLogger) Info

func (l *SlogLogger) Info(ctx context.Context, msg string, args ...any)

Info logs an info-level message.

func (*SlogLogger) Warn

func (l *SlogLogger) Warn(ctx context.Context, msg string, args ...any)

Warn logs a warning-level message.

func (*SlogLogger) With

func (l *SlogLogger) With(args ...any) domain.Logger

With returns a new logger with additional context fields.

type TokenAuth

type TokenAuth struct {
	// Token is the authentication token.
	Token string
}

TokenAuth represents token-based authentication (HTTPS).

The token is transmitted using HTTP Basic Authentication with "git" as the username and the token as the password. This format is compatible with:

  • GitHub personal access tokens
  • GitHub fine-grained tokens
  • GitLab personal access tokens
  • Gitea tokens
  • Azure DevOps personal access tokens

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL