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

Sort output of agent-info #572

Closed
wants to merge 2 commits into from
Closed

Sort output of agent-info #572

wants to merge 2 commits into from

Conversation

zytek
Copy link
Contributor

@zytek zytek commented Dec 12, 2015

Sorting output of agent-info makes it much more user-friendly.

Note: I'm not a Go developer so feel free to refactor it or leave a comment how to improve it. This is just a proposition.

var stats map[string]interface{}
stats, _ = info["stats"]
stats_keys := make([]string, 0, len(stats))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify this as stats_keys := make([]string, len(stats))

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep in mind that stats_keys is not a idiomatic variable notation in Go. It should be statsKeys (camelcase). My 2 cents.

@zytek
Copy link
Contributor Author

zytek commented Dec 17, 2015

Thank you for the comments, I've cleaned up variable names.

One thing got me curious, changing this:

-       statsKeys := make([]string, 0, len(stats))
+       statsKeys := make([]string, len(stats))
-               statsDataKeys := make([]string, 0, len(statsData))
+               statsDataKeys := make([]string, len(statsData))

Made agent-info return a bunch of empy = nil outputs as per this example

serf
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
   = <nil>
  encrypted = false
  event_queue = 0
  event_time = 1
  failed = 0
  intent_queue = 0
  left = 0
  member_time = 1
  members = 1
  query_queue = 0

Can you explain that? Is it because im re-using variables or what?

@dadgar
Copy link
Contributor

dadgar commented Dec 21, 2015

Closing in favor of #617.
@zytek you can see the fix in my commit. You were creating the slice at the desired size and then appending to it, instead of writing the keys in the created indexes.

@dadgar dadgar closed this Dec 21, 2015
@zytek
Copy link
Contributor Author

zytek commented Dec 21, 2015

Thx @dadgar !

BTW, judging by hashicorp/consul#969 - I guess both implementations are fine and it's just a matter of style ;-)

@github-actions
Copy link

github-actions bot commented May 1, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants