This repository was archived by the owner on Aug 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathversion.go
More file actions
67 lines (53 loc) · 1.38 KB
/
version.go
File metadata and controls
67 lines (53 loc) · 1.38 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"github.com/pkg/errors"
)
const (
// Major version
Major = 0
// Minor version
Minor = 1
// PatchSet version
PatchSet = 0
)
var (
// ErrBuildShaNotSet is returned if the build sha was not injected.
ErrBuildShaNotSet = errors.New("build sha not set")
// ErrBuildTimeNotSet is returned if the build time was not injected.
ErrBuildTimeNotSet = errors.New("build time not set")
)
var (
// BuildSha is a git commit sha injected in build time.
BuildSha string
// BuildTime contains a time the binary was built. Injected in build time.
BuildTime string
)
// NewVersion returns a new instance of version object.
func NewVersion() (*Version, error) {
if BuildSha == "" {
return nil, ErrBuildShaNotSet
}
if BuildTime == "" {
return nil, ErrBuildTimeNotSet
}
return &Version{
Major: Major,
Minor: Minor,
PatchSet: PatchSet,
BuildSha: BuildSha,
BuildTime: BuildTime,
}, nil
}
// Version represents an application version, which includes major, minor and patchset versions
// also build sha and build time.
type Version struct {
Major int `json:"major"`
Minor int `json:"minor"`
PatchSet int `json:"patch_set"`
BuildSha string `json:"build_sha"`
BuildTime string `json:"build_time"`
}
func (v Version) String() string {
return fmt.Sprintf("%d.%d.%d - %s ; built on %s", Major, Minor, PatchSet, BuildSha, BuildTime)
}