From dc49596f9c1417101bd566e81e8ae8dd1ef558dc Mon Sep 17 00:00:00 2001 From: derailed Date: Thu, 2 Apr 2020 15:53:31 -0600 Subject: [PATCH] cleaning up --- internal/client/client.go | 4 +++- internal/dao/popeye.go | 5 +++-- internal/model/fish_buff.go | 1 + internal/model/history.go | 1 + internal/render/popeye.go | 15 ++++++++++++--- internal/xray/section.go | 19 +++++++++++-------- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index d83cbea1..190879a8 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -28,7 +28,9 @@ const ( cacheMXKey = "metrics" cacheMXAPIKey = "metricsAPI" checkConnTimeout = 10 * time.Second - CallTimeout = 5 * time.Second + + // CallTimeout represents default api call timeout. + CallTimeout = 5 * time.Second ) var supportedMetricsAPIVersions = []string{"v1beta1"} diff --git a/internal/dao/popeye.go b/internal/dao/popeye.go index 7f828518..d8c74c95 100644 --- a/internal/dao/popeye.go +++ b/internal/dao/popeye.go @@ -101,11 +101,12 @@ func (p *Popeye) List(ctx context.Context, _ string) ([]runtime.Object, error) { return oo, nil } -// Get fetch a resource. -func (a *Popeye) Get(_ context.Context, _ string) (runtime.Object, error) { +// Get retrieves a resource. +func (p *Popeye) Get(_ context.Context, _ string) (runtime.Object, error) { return nil, errors.New("NYI!!") } +// ---------------------------------------------------------------------------- // Helpers... type popFactory struct { diff --git a/internal/model/fish_buff.go b/internal/model/fish_buff.go index b0b2c35e..3f28930e 100644 --- a/internal/model/fish_buff.go +++ b/internal/model/fish_buff.go @@ -32,6 +32,7 @@ func (f *FishBuff) SetSuggestionFn(fn SuggestionFunc) { f.suggestionFn = fn } +// Activate activates the command. func (f *FishBuff) Activate() { if f.suggestionFn == nil { return diff --git a/internal/model/history.go b/internal/model/history.go index 77ede546..3b2677b4 100644 --- a/internal/model/history.go +++ b/internal/model/history.go @@ -14,6 +14,7 @@ func NewHistory(limit int) *History { return &History{limit: limit} } +// List returns the current command history. func (h *History) List() []string { return h.commands } diff --git a/internal/render/popeye.go b/internal/render/popeye.go index 5b07e5db..545338a2 100644 --- a/internal/render/popeye.go +++ b/internal/render/popeye.go @@ -71,9 +71,8 @@ func (Popeye) Render(o interface{}, ns string, r *Row) error { // ---------------------------------------------------------------------------- // Helpers... -// BOZO!! export! type ( - // Builder represents sanitizer + // Builder represents a popeye report. Builder struct { Report Report `json:"popeye" yaml:"popeye"` } @@ -96,9 +95,13 @@ type ( Outcome Outcome `json:"issues,omitempty" yaml:"issues,omitempty"` } + // Outcomes represents a classification of report outcomes Outcome map[string]Issues - Issues []Issue + // Issues represents a collection of issues. + Issues []Issue + + // Issue represents a sanitization issue. Issue struct { Group string `yaml:"group" json:"group"` GVR string `yaml:"gvr" json:"gvr"` @@ -106,16 +109,19 @@ type ( Message string `yaml:"message" json:"message"` } + // Tally tracks a section scores. Tally struct { OK, Info, Warning, Error int Count int } ) +// Sum sums up tally counts. func (t *Tally) Sum() int { return t.OK + t.Info + t.Warning + t.Error } +// Score returns the overall sections score in percent. func (t *Tally) Score() int { oks := t.OK + t.Info return toPerc(float64(oks), float64(oks+t.Warning+t.Error)) @@ -128,14 +134,17 @@ func toPerc(v1, v2 float64) int { return int(math.Floor((v1 / v2) * 100)) } +// Len returns a section length. func (s Sections) Len() int { return len(s) } +// Swap swaps values. func (s Sections) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Less compares section scores. func (s Sections) Less(i, j int) bool { t1, t2 := s[i].Tally, s[j].Tally return t1.Score() < t2.Score() diff --git a/internal/xray/section.go b/internal/xray/section.go index b4883151..edf2ba2d 100644 --- a/internal/xray/section.go +++ b/internal/xray/section.go @@ -29,14 +29,7 @@ func (s *Section) Render(ctx context.Context, ns string, o interface{}) error { return nil } -func cleanse(s string) string { - s = strings.Replace(s, "[", "(", -1) - s = strings.Replace(s, "]", ")", -1) - s = strings.Replace(s, "/", "::", -1) - return s -} - -func (c *Section) outcomeRefs(parent *TreeNode, section render.Section) { +func (*Section) outcomeRefs(parent *TreeNode, section render.Section) { for k, issues := range section.Outcome { p := NewTreeNode(section.GVR, cleanse(k)) parent.Add(p) @@ -58,6 +51,9 @@ func (c *Section) outcomeRefs(parent *TreeNode, section render.Section) { } } +// ---------------------------------------------------------------------------- +// Helpers... + func colorize(s string, l config.Level) string { c := "green" switch l { @@ -70,3 +66,10 @@ func colorize(s string, l config.Level) string { } return fmt.Sprintf("[%s::]%s", c, s) } + +func cleanse(s string) string { + s = strings.Replace(s, "[", "(", -1) + s = strings.Replace(s, "]", ")", -1) + s = strings.Replace(s, "/", "::", -1) + return s +}