🧩
Complete Directive Support
Parse all go.mod directives including module, go, require, replace, exclude, and retract
Parse and analyze go.mod files with ease
package main
import (
"fmt"
"log"
"github.com/scagogogo/go-mod-parser/pkg"
)
func main() {
// Parse a go.mod file
mod, err := pkg.ParseGoModFile("go.mod")
if err != nil {
log.Fatalf("Failed to parse go.mod: %v", err)
}
// Access parsed data
fmt.Printf("Module: %s\n", mod.Name)
fmt.Printf("Go Version: %s\n", mod.GoVersion)
// List dependencies
for _, req := range mod.Requires {
fmt.Printf("- %s %s\n", req.Path, req.Version)
}
}
go get github.com/scagogogo/go-mod-parser