Categorygithub.com/go-toolsmith/pkgload
modulepackage
1.2.2
Repository: https://github.com/go-toolsmith/pkgload.git
Documentation: pkg.go.dev

# README

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.

# Functions

Deduplicate returns a copy of pkgs slice where all duplicated package entries are removed.
LoadPackages with a given config and patterns.
VisitUnits traverses potentially unsorted pkgs list as a set of units.

# Structs

Unit is a set of packages that form a logical group.