contract

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilContracts      = errors.New("contracts cannot be nil")
	ErrUnsupportedFormat = errors.New("unsupported output format")
	ErrNoPackagesFound   = errors.New("no packages found")
	ErrNoGoPackagesFound = errors.New("no Go packages found in directory")
	ErrPackageErrors     = errors.New("package compilation errors")
)

Define static errors

Functions

This section is empty.

Types

type AddedItem

type AddedItem struct {
	Type        string `json:"type"` // "interface", "method", "function", etc.
	Item        string `json:"item"`
	Description string `json:"description"`
}

AddedItem represents a newly added API item

type BreakingChange

type BreakingChange struct {
	Type        string `json:"type"` // "removed_interface", "removed_method", "changed_signature", etc.
	Item        string `json:"item"` // Name of the affected item
	Description string `json:"description"`
	OldValue    string `json:"old_value,omitempty"`
	NewValue    string `json:"new_value,omitempty"`
}

BreakingChange represents a breaking API change

type ConstantContract

type ConstantContract struct {
	Name       string       `json:"name"`
	Package    string       `json:"package"`
	Type       string       `json:"type"`
	Value      string       `json:"value,omitempty"`
	DocComment string       `json:"doc_comment,omitempty"`
	Position   PositionInfo `json:"position"`
}

ConstantContract represents a package-level constant

type Contract

type Contract struct {
	PackageName string              `json:"package_name"`
	ModulePath  string              `json:"module_path,omitempty"`
	Version     string              `json:"version,omitempty"`
	Timestamp   time.Time           `json:"timestamp"`
	Interfaces  []InterfaceContract `json:"interfaces,omitempty"`
	Types       []TypeContract      `json:"types,omitempty"`
	Functions   []FunctionContract  `json:"functions,omitempty"`
	Variables   []VariableContract  `json:"variables,omitempty"`
	Constants   []ConstantContract  `json:"constants,omitempty"`
}

Contract represents the API contract of a Go package or module

func LoadFromFile

func LoadFromFile(filename string) (*Contract, error)

LoadFromFile loads a contract from a JSON file

func (*Contract) SaveToFile

func (c *Contract) SaveToFile(filename string) error

SaveToFile saves the contract to a JSON file

type ContractDiff

type ContractDiff struct {
	PackageName     string           `json:"package_name"`
	OldVersion      string           `json:"old_version,omitempty"`
	NewVersion      string           `json:"new_version,omitempty"`
	BreakingChanges []BreakingChange `json:"breaking_changes,omitempty"`
	AddedItems      []AddedItem      `json:"added_items,omitempty"`
	ModifiedItems   []ModifiedItem   `json:"modified_items,omitempty"`
	Summary         DiffSummary      `json:"summary"`
}

ContractDiff represents differences between two contracts

func LoadDiffFromFile

func LoadDiffFromFile(filename string) (*ContractDiff, error)

LoadDiffFromFile loads a contract diff from a JSON file

func (*ContractDiff) SaveToFile

func (d *ContractDiff) SaveToFile(filename string) error

SaveToFile saves the diff to a JSON file

type DiffSummary

type DiffSummary struct {
	TotalBreakingChanges int  `json:"total_breaking_changes"`
	TotalAdditions       int  `json:"total_additions"`
	TotalModifications   int  `json:"total_modifications"`
	HasBreakingChanges   bool `json:"has_breaking_changes"`
}

DiffSummary provides a high-level summary of changes

type Differ

type Differ struct {
	// IgnorePositions determines whether to ignore source position changes
	IgnorePositions bool
	// IgnoreComments determines whether to ignore documentation comment changes
	IgnoreComments bool
}

Differ handles comparing two API contracts

func NewDiffer

func NewDiffer() *Differ

NewDiffer creates a new contract differ

func (*Differ) Compare

func (d *Differ) Compare(old, new *Contract) (*ContractDiff, error)

Compare compares two contracts and returns the differences

type Extractor

type Extractor struct {
	// IncludePrivate determines whether to include unexported items
	IncludePrivate bool
	// IncludeTests determines whether to include test files
	IncludeTests bool
	// IncludeInternal determines whether to include internal packages
	IncludeInternal bool
}

Extractor handles API contract extraction from Go packages

func NewExtractor

func NewExtractor() *Extractor

NewExtractor creates a new API contract extractor

func (*Extractor) ExtractFromDirectory

func (e *Extractor) ExtractFromDirectory(dir string) (*Contract, error)

ExtractFromDirectory extracts the API contract from a directory containing Go files

func (*Extractor) ExtractFromPackage

func (e *Extractor) ExtractFromPackage(packagePath string) (*Contract, error)

ExtractFromPackage extracts the API contract from a Go package path

type FieldContract

type FieldContract struct {
	Name       string       `json:"name"`
	Type       string       `json:"type"`
	Tag        string       `json:"tag,omitempty"`
	DocComment string       `json:"doc_comment,omitempty"`
	Position   PositionInfo `json:"position"`
}

FieldContract represents a struct field

type FunctionContract

type FunctionContract struct {
	Name       string          `json:"name"`
	Package    string          `json:"package"`
	DocComment string          `json:"doc_comment,omitempty"`
	Parameters []ParameterInfo `json:"parameters,omitempty"`
	Results    []ParameterInfo `json:"results,omitempty"`
	Position   PositionInfo    `json:"position"`
}

FunctionContract represents a function signature

type InterfaceContract

type InterfaceContract struct {
	Name       string           `json:"name"`
	Package    string           `json:"package"`
	DocComment string           `json:"doc_comment,omitempty"`
	Methods    []MethodContract `json:"methods,omitempty"`
	Embedded   []string         `json:"embedded,omitempty"`
	Position   PositionInfo     `json:"position"`
}

InterfaceContract represents an interface definition

type MethodContract

type MethodContract struct {
	Name       string          `json:"name"`
	DocComment string          `json:"doc_comment,omitempty"`
	Receiver   *ReceiverInfo   `json:"receiver,omitempty"`
	Parameters []ParameterInfo `json:"parameters,omitempty"`
	Results    []ParameterInfo `json:"results,omitempty"`
	Position   PositionInfo    `json:"position"`
}

MethodContract represents a method signature

type ModifiedItem

type ModifiedItem struct {
	Type        string `json:"type"`
	Item        string `json:"item"`
	Description string `json:"description"`
	OldValue    string `json:"old_value,omitempty"`
	NewValue    string `json:"new_value,omitempty"`
}

ModifiedItem represents a modified API item (non-breaking)

type ParameterInfo

type ParameterInfo struct {
	Name string `json:"name,omitempty"`
	Type string `json:"type"`
}

ParameterInfo represents parameter or result information

type PositionInfo

type PositionInfo struct {
	Filename string `json:"filename"`
	Line     int    `json:"line"`
	Column   int    `json:"column"`
}

PositionInfo represents source position information

type ReceiverInfo

type ReceiverInfo struct {
	Name    string `json:"name,omitempty"`
	Type    string `json:"type"`
	Pointer bool   `json:"pointer"`
}

ReceiverInfo represents method receiver information

type TypeContract

type TypeContract struct {
	Name       string           `json:"name"`
	Package    string           `json:"package"`
	Kind       string           `json:"kind"` // "struct", "alias", "basic", etc.
	DocComment string           `json:"doc_comment,omitempty"`
	Fields     []FieldContract  `json:"fields,omitempty"`
	Methods    []MethodContract `json:"methods,omitempty"`
	Underlying string           `json:"underlying,omitempty"` // For type aliases
	Position   PositionInfo     `json:"position"`
}

TypeContract represents a type definition (struct, alias, etc.)

type VariableContract

type VariableContract struct {
	Name       string       `json:"name"`
	Package    string       `json:"package"`
	Type       string       `json:"type"`
	DocComment string       `json:"doc_comment,omitempty"`
	Position   PositionInfo `json:"position"`
}

VariableContract represents a package-level variable

Jump to

Keyboard shortcuts

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