Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 1.37 KB

README.md

File metadata and controls

65 lines (49 loc) · 1.37 KB

pkgload

build-img pkg-img reportcard-img version-img

Package pkgload is a set of utilities for go/packages load-related operations.

Installation:

Go version 1.17+

go get github.com/go-toolsmith/pkgload

Example

package main

import (
	"fmt"
	"go/token"

	"github.com/go-toolsmith/pkgload"
	"golang.org/x/tools/go/packages"
)

func main() {
	fset := token.NewFileSet()
	cfg := &packages.Config{
		Mode:  packages.LoadSyntax,
		Tests: true,
		Fset:  fset,
	}

	patterns := []string{"mypackage"}
	pkgs, err := pkgload.LoadPackages(cfg, patterns)
	if err != nil {
		panic(err)
	}

	pkgs = pkgload.Deduplicate(pkgs)

	pkgload.VisitUnits(pkgs, func(u *pkgload.Unit) {
		pkgPath := u.NonNil().PkgPath
		println(pkgPath)
	})
}

License

MIT License.