github.com/sandwich-go/boost@v1.3.29/xdebug/build_info.go (about)

     1  package xdebug
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sandwich-go/boost/version"
     6  	"runtime/debug"
     7  )
     8  
     9  // PrintBuildInfo 输出 build info
    10  func PrintBuildInfo() {
    11  	fmt.Println("Build Version:")
    12  	fmt.Printf("\t%s", version.String())
    13  	fmt.Println()
    14  	if info, ok := debug.ReadBuildInfo(); ok {
    15  		fmt.Println("Main ModuleName:")
    16  		printModule(&info.Main)
    17  		fmt.Println("Dependencies:")
    18  		for _, dep := range info.Deps {
    19  			printModule(dep)
    20  		}
    21  	} else {
    22  		fmt.Println("Built without Go modules")
    23  	}
    24  }
    25  
    26  func printModule(m *debug.Module) {
    27  	fmt.Printf("\t%s", m.Path)
    28  	fmt.Printf("@%s", m.Version)
    29  	if m.Sum != "" {
    30  		fmt.Printf(" (sum: %s)", m.Sum)
    31  	}
    32  	if m.Replace != nil {
    33  		fmt.Printf(" (replace: %s)", m.Replace.Path)
    34  	}
    35  	fmt.Println()
    36  }