gitlab.com/Raven-IO/raven-delve@v1.22.4/pkg/version/buildinfo.go (about)

     1  package version
     2  
     3  import (
     4  	"bytes"
     5  	"runtime/debug"
     6  	"text/template"
     7  )
     8  
     9  func init() {
    10  	buildInfo = moduleBuildInfo
    11  }
    12  
    13  var buildInfoTmpl = ` mod	{{.Main.Path}}	{{.Main.Version}}	{{.Main.Sum}}
    14  {{range .Deps}} dep	{{.Path}}	{{.Version}}	{{.Sum}}{{if .Replace}}
    15  	=> {{.Replace.Path}}	{{.Replace.Version}}	{{.Replace.Sum}}{{end}}
    16  {{end}}`
    17  
    18  func moduleBuildInfo() string {
    19  	info, ok := debug.ReadBuildInfo()
    20  	if !ok {
    21  		return "not built in module mode"
    22  	}
    23  
    24  	buf := new(bytes.Buffer)
    25  	err := template.Must(template.New("buildinfo").Parse(buildInfoTmpl)).Execute(buf, info)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  	return buf.String()
    30  }