Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): git hash info func #26

Closed
wants to merge 1 commit into from

Conversation

joremysh
Copy link
Contributor

@joremysh joremysh commented Nov 8, 2024

Because

  • it helps in debugging with the current running version

This commit

  • add function for reading git hash

image

Copy link

linear bot commented Nov 8, 2024

Comment on lines +6 to +13
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: even if it duplicates the return "" line, a guard error clause makes the code more readable by indenting the non-happy paths.

Suggested change
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
info, ok := debug.ReadBuildInfo()
if !ok {
return ""
}
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
return ""


import "runtime/debug"

var Commit = func() string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this exported variable? Some interesting things to say about it:

  • Why this is needed / when it should be used
  • An example of how it can be used (e.g. a log method call)

@joremysh joremysh closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants