Skip to content

Commit

Permalink
Fix a potential data race on a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Mar 4, 2022
1 parent 3f90bc7 commit 53b6799
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import "runtime/debug"
var v string

func version() string {
if v == "" {
bi, ok := debug.ReadBuildInfo()
if ok {
v = bi.Main.Version
} else {
// if we can't read a go module version then they're using a git
// clone or vendored module so all we can do is report "dev" for
// the version
v = "dev"
}
}
return v
}

func init() {
bi, ok := debug.ReadBuildInfo()
if ok {
v = bi.Main.Version
} else {
// if we can't read a go module version then they're using a git
// clone or vendored module so all we can do is report "dev" for
// the version
v = "dev"
}
}

0 comments on commit 53b6799

Please sign in to comment.