equinixmetal-archive / packngo

[Deprecated] A Golang client for the Equinix Metal API. (Packet is now Equinix Metal)
https://deploy.equinix.com/labs/equinix-sdk-go/
Other
79 stars 53 forks source link

replace Version const with a var determined at runtime #281

Closed displague closed 3 years ago

displague commented 3 years ago

debug.BuildInfo is a way that we can get the packngo version dynamically at runtime. This change will allow us to make automated releases without intervening in the process to update the Version variable contained in version.go

https://golang.org/pkg/runtime/debug/#BuildInfo

https://www.reddit.com/r/golang/comments/lqkkiz/creating_dynamic_version_numbers_in_go_116/

t0mk commented 3 years ago

Looks good. I understand that the version string in a package linking packngo comes from the build info, but I didn't get where is the version for packngo itself set. Is it coming only from git tag or github release?

displague commented 3 years ago

@t0mk That's the best part of this - it would come from the go.mod of the package that is bundling packngo! 😃

I have v0.14.0 in my go.mod for packet-cli, and I replace it to ../ (with the branch checked out, I gave it a testing tag of v0.15.0):

=======[REQUEST]=============
GET /metal/v1/plans HTTP/1.1
Host: api.equinix.com
User-Agent: packet-cli/devel packngo/v0.14.0
Connection: close
Accept: application/json
Content-Type: application/json
X-Auth-Token: **REDACTED**
X-Consumer-Token: Equinix Metal CLI
Accept-Encoding: gzip
displague commented 3 years ago

I had to change UserAgent (which is the default, not the one used by the client) from a const to a var to use the new behavior.