guard

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package guard enforces Portcullis's internal import DAG (design §3).

The architecture allows only a fixed set of import edges between internal packages: domain is a leaf, concrete packages depend only on domain, and a single composition root wires them together. This package encodes those allowed edges and checks them mechanically, so a forbidden import fails the build rather than only being documented. It is the analogue of a structural lint rule, expressed as a test that parses the source tree.

Index

Constants

View Source
const ModulePath = "github.com/JumpTechCode/portcullis"

ModulePath is the Go module path. Internal packages live under ModulePath + "/internal/".

Variables

This section is empty.

Functions

func ScanInternal

func ScanInternal(moduleRoot string) (map[string][]string, error)

ScanInternal parses every non-test .go file under moduleRoot/internal and returns, for each top-level internal package, the sorted unique set of internal packages it imports. Test files are excluded: the architecture invariant constrains production code, and external test packages legitimately import packages a production file may not.

Types

type Violation

type Violation struct {
	// Pkg is the importing internal package's top-level name.
	Pkg string
	// Import is the imported internal package's top-level name, or a marker when
	// Pkg itself is unclassified.
	Import string
}

Violation is a forbidden internal import edge: package Pkg importing package Import, where that edge is not allowed by the DAG.

func Check

func Check(pkg string, internalImports []string) []Violation

Check returns the violations for a single internal package given the top-level names of the internal packages it imports. A package that is not a composition root and is absent from the allowed-edges map yields a single "unclassified" violation. Imports of a package by itself are ignored.

func (Violation) String

func (v Violation) String() string

String renders the violation as a human-readable message.

Jump to

Keyboard shortcuts

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