The Central Go Modules Repository

To use GoCenter:
export GOPROXY=https://gocenter.io
2
Stars
MIT
License
19,691
Downloads
March 29th 2020
Last Modified
Version:
Loading...

Go Report Card GoDoc Build Status

pkgload

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

Installation:

go get -v 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 := packages.Load(cfg, patterns...)
	if err != nil {
		return nil, err
	}
	result := pkgs[:0]
	pkgload.VisitUnits(pkgs, func(u *pkgload.Unit) {
		if u.ExternalTest != nil {
			result = append(result, u.ExternalTest)
		}
		result = append(result, u.Base)
	})
}