Skip to content

Commit

Permalink
use runtime/debug to source linodego Version
Browse files Browse the repository at this point in the history
  • Loading branch information
0xch4z committed May 12, 2021
1 parent b08ff15 commit 3d66283
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 0 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const (
APISecondsPerPoll = 3
// Maximum wait time for retries
APIRetryMaxWaitTime = time.Duration(30) * time.Second
// DefaultUserAgent is the default User-Agent sent in HTTP request headers
DefaultUserAgent = "linodego https://github.com/linode/linodego"
)

var envDebug = false
Expand Down
34 changes: 34 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package linodego

import (
"fmt"
"runtime/debug"
)

const packagePath = "github.com/linode/linodego"

var (
Version = "dev"

// DefaultUserAgent is the default User-Agent sent in HTTP request headers
DefaultUserAgent string
)

// init attempts to source the version from the build info injected
// at runtime and sets the DefaultUserAgent.
func init() {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range buildInfo.Deps {
if dep.Path == packagePath {
if dep.Replace != nil {
Version = dep.Replace.Version
}
Version = dep.Version
break
}
}
}

DefaultUserAgent = fmt.Sprintf("linodego/%s https://github.com/linode/linodego", Version)
}

0 comments on commit 3d66283

Please sign in to comment.