From 53b6799deeaf7f39b456449bf9ad263a4c44f51e Mon Sep 17 00:00:00 2001 From: Pior Bastida Date: Fri, 4 Mar 2022 14:56:05 -0500 Subject: [PATCH] Fix a potential data race on a global variable --- version.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/version.go b/version.go index 590329ef84..63b9b4de9f 100644 --- a/version.go +++ b/version.go @@ -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" + } +}