-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.go
More file actions
33 lines (29 loc) · 878 Bytes
/
Copy pathrelease.go
File metadata and controls
33 lines (29 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Package znserver carries the release metadata in release.json into every build.
package znserver
import (
_ "embed"
"encoding/json"
"strings"
)
// Compiled in rather than read at startup: the Docker image and the release
// binaries ship without release.json, and a relative read would depend on the
// directory the server was launched from.
//
//go:embed release.json
var releaseJSON []byte
// Version is the version field of release.json at build time. It returns
// "undefined" instead of failing when that field is missing or malformed.
func Version() string {
return versionFrom(releaseJSON)
}
func versionFrom(raw []byte) string {
var release struct {
Version string `json:"version"`
}
if err := json.Unmarshal(raw, &release); err == nil {
if version := strings.TrimSpace(release.Version); version != "" {
return version
}
}
return "undefined"
}