Help us shape the future of Go! Take the 2026 Go Developer Survey

detector

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package detector provides build strategy detection for repositories.

Package detector provides build strategy detection for repositories.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLanguageDetected is returned when no language can be detected.
	ErrNoLanguageDetected = errors.New("could not detect application language")

	// ErrMultipleLanguages is returned when multiple languages are detected.
	ErrMultipleLanguages = errors.New("multiple languages detected, please specify strategy")

	// ErrUnsupportedLanguage is returned when the detected language is not supported.
	ErrUnsupportedLanguage = errors.New("detected language is not supported")

	// ErrRepositoryAccessFailed is returned when the repository cannot be accessed.
	ErrRepositoryAccessFailed = errors.New("failed to access repository")

	// ErrInvalidGoMod is returned when go.mod cannot be parsed.
	ErrInvalidGoMod = errors.New("failed to parse go.mod")

	// ErrInvalidPackageJSON is returned when package.json cannot be parsed.
	ErrInvalidPackageJSON = errors.New("failed to parse package.json")

	// ErrInvalidCargoToml is returned when Cargo.toml cannot be parsed.
	ErrInvalidCargoToml = errors.New("failed to parse Cargo.toml")

	// ErrInvalidPyProject is returned when pyproject.toml cannot be parsed.
	ErrInvalidPyProject = errors.New("failed to parse pyproject.toml")

	// ErrNoEntryPointsFound is returned when no entry points are detected in the repository.
	// **Validates: Requirements 19.6**
	ErrNoEntryPointsFound = errors.New("no entry points found in repository")
)

Detection errors.

View Source
var CGOPackages = []string{

	"github.com/mattn/go-sqlite3",

	"github.com/miekg/pkcs11",
	"github.com/spacemonkeygo/openssl",

	"github.com/shirou/gopsutil",

	"github.com/therecipe/qt",
	"fyne.io/fyne",

	"github.com/tecbot/gorocksdb",
	"github.com/linxGnu/grocksdb",

	"github.com/jmhodges/levigo",

	"github.com/gographics/imagick",
	"gopkg.in/gographics/imagick.v2",
	"gopkg.in/gographics/imagick.v3",

	"github.com/giorgisio/goav",
	"github.com/3d0c/gmf",

	"github.com/DataDog/zstd",
	"github.com/valyala/gozstd",

	"github.com/google/gopacket",

	"gorgonia.org/tensor",
	"github.com/tensorflow/tensorflow/tensorflow/go",
}

CGOPackages lists common packages that require CGO. These are well-known packages that use C bindings. **Validates: Requirements 16.1, 1.3**

View Source
var GoEntryPointDirs = []string{
	"cmd",
	"apps",
	"services",
}

GoEntryPointDirs lists directories to check for main packages in Go repositories. **Validates: Requirements 19.1, 19.2, 19.3, 19.4**

Functions

func DetermineBuildType

func DetermineBuildType(strategy models.BuildStrategy) models.BuildType

DetermineBuildType returns the build type based on the build strategy. This is the ONLY place build type is determined automatically. **Feature: platform-enhancements, Property 1: Build Type Determination** **Validates: Requirements 4.1, 4.2, 4.7, 4.8**

Rules: - If strategy is "dockerfile" → build_type is "oci" - For all other strategies → build_type is "pure-nix"

func DetermineBuildTypeFromLanguage

func DetermineBuildTypeFromLanguage(language string) (models.BuildStrategy, models.BuildType)

DetermineBuildTypeFromLanguage returns the build type based on the selected language. This is used when a user selects a language (Go, Rust, Python, Node.js, Dockerfile) during service creation. **Validates: Requirements 4.1, 4.2, 4.7, 4.8**

Rules: - If language is "dockerfile" → build_type is "oci", strategy is "dockerfile" - For Go → build_type is "pure-nix", strategy is "auto-go" - For Rust → build_type is "pure-nix", strategy is "auto-rust" - For Python → build_type is "pure-nix", strategy is "auto-python" - For Node.js → build_type is "pure-nix", strategy is "auto-node"

func HasGoWorkspace

func HasGoWorkspace(repoPath string) bool

HasGoWorkspace checks if a repository contains a go.work file. This is a convenience function for quick workspace detection. **Validates: Requirements 22.1**

func IsCGOPackage

func IsCGOPackage(pkgPath string) bool

IsCGOPackage checks if a package path is a known CGO-requiring package.

func IsOCIOnlyStrategy

func IsOCIOnlyStrategy(strategy models.BuildStrategy) bool

IsOCIOnlyStrategy returns true if the strategy requires OCI build type. Currently, only the dockerfile strategy requires OCI. **Validates: Requirements 4.7, 4.8**

Types

type AutoDetector

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

AutoDetector provides priority-based detection for repositories. Detection priority: flake > language-specific > dockerfile

func NewAutoDetector

func NewAutoDetector() *AutoDetector

NewAutoDetector creates a new AutoDetector.

func (*AutoDetector) Detect

func (a *AutoDetector) Detect(ctx context.Context, repoPath string) (*models.DetectionResult, error)

Detect performs auto-detection on a repository. It follows the priority: flake > language > dockerfile.

func (*AutoDetector) DetectAll

func (a *AutoDetector) DetectAll(ctx context.Context, repoPath string) ([]*models.DetectionResult, error)

DetectAll returns all detected languages/frameworks in the repository. This is useful for handling mixed-language repositories.

func (*AutoDetector) DetectWithPreference

func (a *AutoDetector) DetectWithPreference(ctx context.Context, repoPath string, preference models.BuildStrategy) (*models.DetectionResult, error)

DetectWithPreference performs detection with a user preference. If the user prefers a specific strategy, it validates that strategy is applicable.

func (*AutoDetector) GetRecommendedStrategy

func (a *AutoDetector) GetRecommendedStrategy(ctx context.Context, repoPath string) (*StrategyRecommendation, error)

GetRecommendedStrategy returns the recommended strategy for a repository. It considers the detected languages and provides reasoning.

func (*AutoDetector) IsMixedLanguageRepo

func (a *AutoDetector) IsMixedLanguageRepo(ctx context.Context, repoPath string) (bool, []models.BuildStrategy)

IsMixedLanguageRepo checks if a repository contains multiple languages.

func (*AutoDetector) ValidateStrategy

func (a *AutoDetector) ValidateStrategy(ctx context.Context, repoPath string, strategy models.BuildStrategy) error

ValidateStrategy checks if a strategy is valid for the given repository.

type CGOResult

type CGOResult struct {
	// RequiresCGO indicates whether the project requires CGO
	RequiresCGO bool `json:"requires_cgo"`

	// Reason explains why CGO is required (or not)
	Reason string `json:"reason,omitempty"`

	// DetectedPackages lists the packages that triggered CGO detection
	DetectedPackages []string `json:"detected_packages,omitempty"`

	// HasCImport indicates if any file has `import "C"`
	HasCImport bool `json:"has_c_import"`

	// HasCGODirectives indicates if any file has CGO directives
	HasCGODirectives bool `json:"has_cgo_directives"`
}

CGOResult contains the result of CGO detection.

func DetectCGO

func DetectCGO(repoPath string) (*CGOResult, error)

DetectCGO checks if a Go project requires CGO. It scans the repository for: 1. Known CGO-requiring packages in go.mod 2. `import "C"` statements in Go files 3. CGO-related build directives

**Validates: Requirements 16.1**

type DefaultDetector

type DefaultDetector struct{}

DefaultDetector is the default implementation of the Detector interface.

func NewDetector

func NewDetector() *DefaultDetector

NewDetector creates a new DefaultDetector.

func (*DefaultDetector) Detect

func (d *DefaultDetector) Detect(ctx context.Context, repoPath string) (*models.DetectionResult, error)

Detect analyzes the repository and returns detection results. It uses priority-based detection: flake > language > dockerfile.

func (*DefaultDetector) DetectGo

func (d *DefaultDetector) DetectGo(ctx context.Context, repoPath string) (*models.DetectionResult, error)

DetectGo checks for Go application markers.

func (*DefaultDetector) DetectNode

func (d *DefaultDetector) DetectNode(ctx context.Context, repoPath string) (*models.DetectionResult, error)

DetectNode checks for Node.js application markers.

func (*DefaultDetector) DetectPython

func (d *DefaultDetector) DetectPython(ctx context.Context, repoPath string) (*models.DetectionResult, error)

DetectPython checks for Python application markers.

func (*DefaultDetector) DetectRust

func (d *DefaultDetector) DetectRust(ctx context.Context, repoPath string) (*models.DetectionResult, error)

DetectRust checks for Rust application markers.

func (*DefaultDetector) HasDockerfile

func (d *DefaultDetector) HasDockerfile(ctx context.Context, repoPath string) bool

HasDockerfile checks if repository has a Dockerfile.

func (*DefaultDetector) HasFlake

func (d *DefaultDetector) HasFlake(ctx context.Context, repoPath string) bool

HasFlake checks if repository has a flake.nix.

type Detector

type Detector interface {
	// Detect analyzes the repository and returns detection results.
	Detect(ctx context.Context, repoPath string) (*models.DetectionResult, error)

	// DetectGo checks for Go application markers.
	DetectGo(ctx context.Context, repoPath string) (*models.DetectionResult, error)

	// DetectNode checks for Node.js application markers.
	DetectNode(ctx context.Context, repoPath string) (*models.DetectionResult, error)

	// DetectRust checks for Rust application markers.
	DetectRust(ctx context.Context, repoPath string) (*models.DetectionResult, error)

	// DetectPython checks for Python application markers.
	DetectPython(ctx context.Context, repoPath string) (*models.DetectionResult, error)

	// HasFlake checks if repository has a flake.nix.
	HasFlake(ctx context.Context, repoPath string) bool

	// HasDockerfile checks if repository has a Dockerfile.
	HasDockerfile(ctx context.Context, repoPath string) bool
}

Detector analyzes repositories to determine build strategy.

type GoWorkspaceResult

type GoWorkspaceResult struct {
	// IsWorkspace indicates whether a go.work file was found
	IsWorkspace bool `json:"is_workspace"`

	// GoVersion is the Go version specified in go.work (if any)
	GoVersion string `json:"go_version,omitempty"`

	// Modules lists the module paths specified in the use directives
	Modules []string `json:"modules,omitempty"`
}

GoWorkspaceResult contains the result of Go workspace detection. **Validates: Requirements 22.1, 22.4**

func DetectGoWorkspace

func DetectGoWorkspace(repoPath string) (*GoWorkspaceResult, error)

DetectGoWorkspace checks if a repository contains a go.work file and parses its contents. **Validates: Requirements 22.1, 22.4**

type PackageJSON

type PackageJSON struct {
	Name            string            `json:"name"`
	Version         string            `json:"version"`
	Main            string            `json:"main"`
	Scripts         map[string]string `json:"scripts"`
	Dependencies    map[string]string `json:"dependencies"`
	DevDependencies map[string]string `json:"devDependencies"`
	Engines         struct {
		Node string `json:"node"`
		NPM  string `json:"npm"`
	} `json:"engines"`
	PackageManager string `json:"packageManager"`
}

PackageJSON represents the structure of a package.json file.

type StrategyRecommendation

type StrategyRecommendation struct {
	Strategy     models.BuildStrategy   `json:"strategy"`
	Reason       string                 `json:"reason"`
	Confidence   float64                `json:"confidence"`
	Alternatives []models.BuildStrategy `json:"alternatives,omitempty"`
}

StrategyRecommendation contains a recommended strategy with reasoning.

Jump to

Keyboard shortcuts

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