detection

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDetectors = []Detector{
		Go,
		Javascript,
		Python,
		Ruby,
		Custom,
	}

	DetectorsByFlag = map[string]Detector{
		"django":     Django,
		"flask":      Flask,
		"go":         Go,
		"javascript": Javascript,
		"nextjs":     NextJS,
		"python":     Python,
		"rails":      Rails,
		"ruby":       Ruby,
		"sinatra":    Sinatra,
	}

	PositiveDetectionMessage = "%s project detected with confidence level %s!\n"
)
View Source
var (
	Django = &FileDetector{
		Title:             "Django",
		Paths:             []string{"manage.py"},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryPython,
	}
	Flask = &FileDetector{
		Title:             "Flask",
		Paths:             []string{"app.py"},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryPython,
	}

	Rails = &FileDetector{
		Title: "Ruby on Rails",
		Paths: []string{
			"config.ru", "app", "config", "db", "lib", "public", "vendor",
		},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryRuby,
	}
	Sinatra = &FileDetector{
		Title: "Sinatra",
		Paths: []string{
			"app.rb",
		},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryRuby,
		RequiredFiles:     []string{"app.rb"},
	}
)
View Source
var (
	Custom = &FileDetector{
		Title:             "Custom",
		Paths:             []string{},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryCustom,
	}

	Go = &FileDetector{
		Title:             "Go",
		Paths:             []string{"main.go", "go.mod", "go.sum"},
		FollowUpDetectors: nil,
		AnchorCategory:    anchorcli.CategoryGo,
	}

	Javascript = &FileDetector{
		Title:             "JavaScript",
		Paths:             []string{"package.json", "index.js", "app.js"},
		FollowUpDetectors: []Detector{NextJS},
		AnchorCategory:    anchorcli.CategoryJavascript,
	}

	Python = &FileDetector{
		Title:             "Python",
		Paths:             []string{"requirements.txt"},
		FollowUpDetectors: []Detector{Django, Flask},
		AnchorCategory:    anchorcli.CategoryPython,
	}

	Ruby = &FileDetector{
		Title:             "Ruby",
		Paths:             []string{"Gemfile", "Gemfile.lock", "Rakefile"},
		FollowUpDetectors: []Detector{Rails, Sinatra},
		AnchorCategory:    anchorcli.CategoryRuby,
	}
)
View Source
var NextJS = &NextJSDetector{}

Functions

This section is empty.

Types

type Confidence

type Confidence int

Confidence represents the confidence score

const (
	High   Confidence = 100
	Medium Confidence = 60
	Low    Confidence = 40
	None   Confidence = 0
)

Different confidence levels

func (Confidence) String

func (s Confidence) String() string

Confidence.String() returns the string representation of the confidence level

type Detector

type Detector interface {
	GetTitle() string
	Detect(FS) (Match, error)
	FollowUp() []Detector
}

Detector interface represents a project detector

type FS added in v0.0.9

type FS interface {
	fs.ReadFileFS
	fs.StatFS
}

type FileDetector

type FileDetector struct {
	Title             string
	Paths             []string
	RequiredFiles     []string
	FollowUpDetectors []Detector
	AnchorCategory    *anchorcli.Category
}

FileDetector is a generic file-based project detector

func (FileDetector) Detect

func (fd FileDetector) Detect(dirFS FS) (Match, error)

Detect checks if the directory contains any of the specified files

func (FileDetector) FollowUp

func (fd FileDetector) FollowUp() []Detector

FollowUp returns additional detectors

func (FileDetector) GetTitle

func (fd FileDetector) GetTitle() string

GetTitle returns the name of the detector

type Match

type Match struct {
	Detector   Detector
	Detected   bool
	Confidence Confidence
	// MissingRequiredFiles represents a list of files that are required but missing.
	MissingRequiredFiles []string
	FollowUpDetectors    []Detector
	Details              string
	AnchorCategory       *anchorcli.Category
}

Match holds the detection result, confidence, and follow-up detectors

type NextJSDetector added in v0.0.9

type NextJSDetector struct {
	FollowUpDetectors []Detector
}

func (NextJSDetector) Detect added in v0.0.9

func (d NextJSDetector) Detect(dirFS FS) (Match, error)

func (NextJSDetector) FollowUp added in v0.0.9

func (d NextJSDetector) FollowUp() []Detector

func (NextJSDetector) GetTitle added in v0.0.9

func (d NextJSDetector) GetTitle() string

type PackageManager

type PackageManager string
const (
	RubyGemsPkgManager PackageManager = "rubygems"
	NPMPkgManager      PackageManager = "npm"
	YarnPkgManager     PackageManager = "yarn"
)

func (PackageManager) String

func (pm PackageManager) String() string

type PackageManagerManifest

type PackageManagerManifest string
const (
	Gemfile         PackageManagerManifest = "Gemfile"
	GemfileLock     PackageManagerManifest = "Gemfile.lock"
	PackageJSON     PackageManagerManifest = "package.json"
	PackageLockJSON PackageManagerManifest = "package-lock.json"
	YarnLock        PackageManagerManifest = "yarn.lock"
)

func (PackageManagerManifest) String

func (pmm PackageManagerManifest) String() string

type Results

type Results map[Confidence][]Match

func Perform

func Perform(detectors []Detector, dirFS FS) (Results, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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