-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use runtime/debug to source linodego Version
- Loading branch information
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |