All initial funcs plus module info.

This commit is contained in:
Alex 2020-10-03 17:43:46 +02:00
parent 6bc36d3b18
commit 55cf60501d
2 changed files with 67 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/version-go/ldflags
go 1.13

64
version.go Normal file
View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2020 Alex <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex <alex@webz.asia>
* @since 03.10.2020
*
*/
package ldflags
type buildInfo struct {
version string
hash string
time string
}
var (
buildVersion = "unknown"
buildHash = "unknown"
buildTime = "unknown"
info *buildInfo
)
func init() {
info = New()
}
// New works as a singleton
func New() *buildInfo {
if info == nil {
info = &buildInfo{
buildVersion, buildHash, buildTime,
}
}
return info
}
// Version returns build version if provided, "unknown" otherwise
func Version() string {
return info.version
}
// Build returns build hash if provided, "unknown" otherwise
func Build() string {
return info.hash
}
// Time returns build time if provided, "unknown" otherwise
func Time() string {
return info.time
}