github.com/april1989/origin-go-tools@v0.0.32/internal/lsp/debug/info.1.12.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build go1.12
     6  
     7  package debug
     8  
     9  import (
    10  	"fmt"
    11  	"io"
    12  	"runtime/debug"
    13  )
    14  
    15  func printBuildInfo(w io.Writer, verbose bool, mode PrintMode) {
    16  	if info, ok := debug.ReadBuildInfo(); ok {
    17  		fmt.Fprintf(w, "%v %v\n", info.Path, Version)
    18  		printModuleInfo(w, &info.Main, mode)
    19  		if verbose {
    20  			for _, dep := range info.Deps {
    21  				printModuleInfo(w, dep, mode)
    22  			}
    23  		}
    24  	} else {
    25  		fmt.Fprintf(w, "version %s, built in $GOPATH mode\n", Version)
    26  	}
    27  }
    28  
    29  func printModuleInfo(w io.Writer, m *debug.Module, mode PrintMode) {
    30  	fmt.Fprintf(w, "    %s@%s", m.Path, m.Version)
    31  	if m.Sum != "" {
    32  		fmt.Fprintf(w, " %s", m.Sum)
    33  	}
    34  	if m.Replace != nil {
    35  		fmt.Fprintf(w, " => %v", m.Replace.Path)
    36  	}
    37  	fmt.Fprintf(w, "\n")
    38  }