Skip to content

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

License

Notifications You must be signed in to change notification settings

go-toolsmith/pkgload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages