github.com/rivy-go/git-changelog@v0.0.0-20240424224517-b86e6ab57773/cmd/git-changelog/version-go1.12-to-ltgo1.18.go (about)

     1  //go:build go1.12 && !go1.18
     2  // +build go1.12,!go1.18
     3  
     4  package main
     5  
     6  import (
     7  	"runtime/debug"
     8  )
     9  
    10  // ref: [Go 1.18 debug/buildinfo features](https://shibumi.dev/posts/go-18-feature) @@ <https://archive.is/4LeZV>
    11  // ref: [How to include Git version information in Go](https://blog.carlmjohnson.net/post/2023/golang-git-hash-how-to) @@ <https://archive.is/SmRbl>
    12  // ref: <https://stackoverflow.com/questions/71642366/how-do-you-read-debug-vcs-version-info-from-a-go-1-18-binary> @@ <https://archive.is/CF6yk>
    13  
    14  // `debug.BuildInfo` is available from Go 1.12
    15  
    16  func version_impl(_options FnVersionOptions) string {
    17  	if info, ok := debug.ReadBuildInfo(); ok {
    18  		if info.Main.Version != "" && (info.Main.Version != "(devel)" /* a local build */) {
    19  			return info.Main.Version
    20  		}
    21  	}
    22  	if VersionFromBuilder != "" {
    23  		return VersionFromBuilder
    24  	}
    25  	return Version + "+"
    26  }