Skip to content

Commit

Permalink
test go version
Browse files Browse the repository at this point in the history
  • Loading branch information
xiantang committed Oct 16, 2023
1 parent edf6d29 commit 1c66a49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 22 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println

Check failure on line 6 in main.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

undefined: Println
"os"
"os/signal"
"runtime"
"runtime/debug"
"syscall"

Expand Down Expand Up @@ -44,18 +45,34 @@ func parseFlag(args []string) {
flag.CommandLine.Parse(args)
}

func versionInfo() *debug.BuildInfo {
if info, ok := debug.ReadBuildInfo(); ok {
return info
}
return nil
}

func main() {
bi, ok := debug.ReadBuildInfo()
if ok {
fmt.Printf("bi: %v\n", bi)
versionInfo := versionInfo()
var goVersion string
var airVersion string
if versionInfo != nil {
goVersion = versionInfo.GoVersion
airVersion = versionInfo.Main.Version
} else {
airVersion = "(unknown version)"
goVersion = runtime.Version()
}
goversion := bi.GoVersion
// TODO: how to get the version of the binary? gofumpt
// https://github.com/cosmtrek/air/issues/434 but just get devel :(
// https: // www.reddit.com/r/golang/comments/udhml7/best_way_to_embed_version_info_into_binary/
// go embed maybe a good idea
fmt.Printf(`
__ _ ___
/ /\ | | | |_)
/_/--\ |_| |_| \_ %s, built with Go %s
`, airVersion, goversion)
`, airVersion, goVersion)

if showVersion {
return
Expand Down
6 changes: 4 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package main

var airVersion string
var goVersion string
var (
airVersion string
goVersion string
)

0 comments on commit 1c66a49

Please sign in to comment.