From c9f6ebc9664a8c14e1f63bf239d57027040f4919 Mon Sep 17 00:00:00 2001 From: shubham Date: Fri, 30 Oct 2020 19:17:32 +0530 Subject: [PATCH] Fix out of order status codes in gui --- gui/drawer.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gui/drawer.go b/gui/drawer.go index a4934e9..81aaf69 100644 --- a/gui/drawer.go +++ b/gui/drawer.go @@ -3,6 +3,7 @@ package gui import ( "context" "fmt" + "sort" "sync" "time" @@ -213,11 +214,17 @@ func (d *drawer) redrawMetrics(ctx context.Context) { m.End.Format(time.RFC3339), ), text.WriteReplace()) - // TODO: Guaranteed to be in order. + // To guarantee that status codes are in order + // taking the slice of keys and sorting them. codesText := "" - for code, n := range m.StatusCodes { + var keys []string + for k := range m.StatusCodes { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { codesText += fmt.Sprintf(`%q: %d -`, code, n) +`, k, m.StatusCodes[k]) } d.widgets.statusCodesText.Write(codesText, text.WriteReplace())