Source File
visit.go
Belonging Package
golang.org/x/tools/go/packages
// Copyright 2018 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package packagesimport ()// Visit visits all the packages in the import graph whose roots are// pkgs, calling the optional pre function the first time each package// is encountered (preorder), and the optional post function after a// package's dependencies have been visited (postorder).// The boolean result of pre(pkg) determines whether// the imports of package pkg are visited.//// Example://// pkgs, err := Load(...)// if err != nil { ... }// Visit(pkgs, nil, func(pkg *Package) {// log.Println(pkg)// })//// In most cases, it is more convenient to use [Postorder]://// for pkg := range Postorder(pkgs) {// log.Println(pkg)// }func ( []*Package, func(*Package) bool, func(*Package)) {:= make(map[*Package]bool)var func(*Package)= func( *Package) {if ![] {[] = trueif == nil || () {for , := range moremaps.Sorted(.Imports) { // for determinism()}}if != nil {()}}}for , := range {()}}// PrintErrors prints to os.Stderr the accumulated errors of all// packages in the import graph rooted at pkgs, dependencies first.// PrintErrors returns the number of errors printed.func ( []*Package) int {var int:= make(map[*Module]bool)for := range Postorder() {for , := range .Errors {fmt.Fprintln(os.Stderr, )++}// Print pkg.Module.Error once if present.:= .Moduleif != nil && .Error != nil && ![] {[] = truefmt.Fprintln(os.Stderr, .Error.Err)++}}return}// Postorder returns an iterator over the packages in// the import graph whose roots are pkg.// Packages are enumerated in dependencies-first order.func ( []*Package) iter.Seq[*Package] {return func( func(*Package) bool) {:= make(map[*Package]bool)var func(*Package) bool= func( *Package) bool {if ![] {[] = truefor , := range moremaps.Sorted(.Imports) { // for determinismif !() {return false}}if !() {return false}}return true}for , := range {if !() {break}}}}
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)