5b24a6d5490134305e3d6737eee5b2ba49c2df03
[govpp.git] / version / version.go
1 //  Copyright (c) 2019 Cisco and/or its affiliates.
2 //
3 //  Licensed under the Apache License, Version 2.0 (the "License");
4 //  you may not use this file except in compliance with the License.
5 //  You may obtain a copy of the License at:
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 //  Unless required by applicable law or agreed to in writing, software
10 //  distributed under the License is distributed on an "AS IS" BASIS,
11 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //  See the License for the specific language governing permissions and
13 //  limitations under the License.
14
15 package version
16
17 import (
18         "fmt"
19         "runtime"
20         "strconv"
21         "time"
22 )
23
24 var (
25         name        = "govpp"
26         version     = "v0.0.0+unknown"
27         commitHash  = "unknown"
28         buildBranch = "HEAD"
29         buildStamp  = ""
30         buildUser   = ""
31         buildHost   = ""
32
33         buildDate time.Time
34 )
35
36 func init() {
37         buildstampInt64, _ := strconv.ParseInt(buildStamp, 10, 64)
38         if buildstampInt64 == 0 {
39                 buildstampInt64 = time.Now().Unix()
40         }
41         buildDate = time.Unix(buildstampInt64, 0)
42 }
43
44 func Info() string {
45         return fmt.Sprintf(`%s %s`, name, version)
46 }
47
48 func Verbose() string {
49         return fmt.Sprintf(`%s
50   Version:      %s
51   Branch:       %s
52   Revision:     %s
53   Built by:     %s@%s 
54   Build date:   %s
55   Go runtime:   %s (%s/%s)`,
56                 name,
57                 version, buildBranch, commitHash,
58                 buildUser, buildHost, buildDate.Format(time.UnixDate),
59                 runtime.Version(), runtime.GOOS, runtime.GOARCH,
60         )
61 }