init commit
This commit is contained in:
30
pkg/version/version.go
Normal file
30
pkg/version/version.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Version is set at build time or read from file
|
||||
var Version = "dev"
|
||||
|
||||
// Get returns the application version
|
||||
func Get() string {
|
||||
if Version != "dev" {
|
||||
return Version
|
||||
}
|
||||
|
||||
// Try to read from VERSION file at runtime (for development)
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if ok {
|
||||
root := filepath.Join(filepath.Dir(filename), "..", "..")
|
||||
data, err := os.ReadFile(filepath.Join(root, "VERSION"))
|
||||
if err == nil {
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
}
|
||||
|
||||
return Version
|
||||
}
|
||||
Reference in New Issue
Block a user