1
1
package buildinfo
2
2
3
3
import (
4
- "path "
4
+ "fmt "
5
5
"runtime/debug"
6
6
"sync"
7
7
"time"
@@ -14,36 +14,50 @@ var (
14
14
buildInfoValid bool
15
15
readBuildInfo sync.Once
16
16
17
+ externalURL string
18
+ readExternalURL sync.Once
19
+
20
+ version string
21
+ readVersion sync.Once
22
+
17
23
// Injected with ldflags at build!
18
24
tag string
19
25
)
20
26
21
27
// Version returns the semantic version of the build.
22
28
// Use golang.org/x/mod/semver to compare versions.
23
29
func Version () string {
24
- revision , valid := revision ()
25
- if valid {
26
- revision = "+" + revision [:7 ]
27
- }
28
- if tag == "" {
29
- return "v0.0.0-devel" + revision
30
- }
31
- if semver .Build (tag ) == "" {
32
- tag += revision
33
- }
34
- return "v" + tag
30
+ readVersion .Do (func () {
31
+ revision , valid := revision ()
32
+ if valid {
33
+ revision = "+" + revision [:7 ]
34
+ }
35
+ if tag == "" {
36
+ version = "v0.0.0-devel" + revision
37
+ return
38
+ }
39
+ if semver .Build (tag ) == "" {
40
+ tag += revision
41
+ }
42
+ version = "v" + tag
43
+ })
44
+ return version
35
45
}
36
46
37
47
// ExternalURL returns a URL referencing the current Coder version.
38
48
// For production builds, this will link directly to a release.
39
49
// For development builds, this will link to a commit.
40
50
func ExternalURL () string {
41
- repo := "https://github.com/coder/coder"
42
- revision , valid := revision ()
43
- if ! valid {
44
- return repo
45
- }
46
- return path .Join (repo , "commit" , revision )
51
+ readExternalURL .Do (func () {
52
+ repo := "https://github.com/coder/coder"
53
+ revision , valid := revision ()
54
+ if ! valid {
55
+ externalURL = repo
56
+ return
57
+ }
58
+ externalURL = fmt .Sprintf ("%s/commit/%s" , repo , revision )
59
+ })
60
+ return externalURL
47
61
}
48
62
49
63
// Time returns when the Git revision was published.
0 commit comments