Skip to content

Commit

Permalink
Merge pull request #379 from openziti/add-version-provider-mock
Browse files Browse the repository at this point in the history
Add a default version provider
  • Loading branch information
plorenz authored Aug 30, 2023
2 parents ada2305 + 326d838 commit 9f0ece1
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions versions/version_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package versions

import (
"runtime"
"runtime/debug"
"time"
)

type DefaultVersionProvider struct {
SourceBranch string
VersionInfo
}

func (v DefaultVersionProvider) Branch() string {
return v.SourceBranch
}

func (v DefaultVersionProvider) EncoderDecoder() VersionEncDec {
return &StdVersionEncDec
}

func (v DefaultVersionProvider) Version() string {
return v.VersionInfo.Version
}

func (v DefaultVersionProvider) BuildDate() string {
return v.VersionInfo.BuildDate
}

func (v DefaultVersionProvider) Revision() string {
return v.VersionInfo.Revision
}

func (v DefaultVersionProvider) AsVersionInfo() *VersionInfo {
return &v.VersionInfo
}

func NewDefaultVersionProvider() VersionProvider {
buildInfo, ok := debug.ReadBuildInfo()
rev := ""
if ok {
for _, kv := range buildInfo.Settings {
if kv.Key == "vcs.revision" {
rev = kv.Value
}
}
}
return &DefaultVersionProvider{
VersionInfo: VersionInfo{
Version: "v0.0.0",
Revision: rev,
BuildDate: time.Now().String(),
OS: runtime.GOOS,
Arch: runtime.GOARCH,
},
}
}

0 comments on commit 9f0ece1

Please sign in to comment.