module

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package module provides Go module discovery and dependency operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseGoMod

func ParseGoMod(path string) (modulePath string, deps []string, err error)

ParseGoMod reads and parses a go.mod file. Returns the module path and direct dependencies.

func UpdateGoMod

func UpdateGoMod(path string, root string, versions map[string]string) error

UpdateGoMod updates internal dependency versions in a go.mod file.

Parameters:

  • path: Path to go.mod file
  • root: Root module path (to identify internal deps)
  • versions: Map of module short name -> new version

Types

type Graph

type Graph struct {
	Root    *Module
	Modules map[string]*Module // Short name -> Module (empty string key for root)
}

Graph represents the module dependency graph.

func Discover

func Discover(dir string) (*Graph, error)

Discover finds all Go modules in a directory tree. Returns a Graph containing the root module and all submodules.

func (*Graph) AllModules

func (g *Graph) AllModules() []*Module

AllModules returns all modules as a slice, sorted by short name.

func (*Graph) Dependents

func (g *Graph) Dependents(shortName string) []*Module

Dependents returns modules that depend on the given module.

func (*Graph) FindModule

func (g *Graph) FindModule(shortName string) *Module

FindModule returns a module by short name. Use empty string to get the root module.

func (*Graph) IsInternal

func (g *Graph) IsInternal(modulePath string) bool

IsInternal returns true if the module path is internal to this repo.

func (*Graph) TopologicalSort

func (g *Graph) TopologicalSort() []*Module

TopologicalSort returns modules in dependency order (leaves first). Modules with no dependencies come first, then modules that only depend on those, and so on. This ensures that when processing modules in order, all dependencies are processed before dependents.

type Module

type Module struct {
	Name         string   // Full module path (e.g., "github.com/gojekfarm/xtools/xkafka")
	ShortName    string   // Relative to root (e.g., "xkafka"), empty for root module
	Path         string   // Filesystem path to module directory
	Dependencies []string // Internal module dependencies (short names)
}

Module represents a Go module in the repository.

Jump to

Keyboard shortcuts

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