From 0ddf4e9a50e1824eecafdd0556cfcee231c03a90 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Mon, 1 Jun 2020 12:44:59 +0200 Subject: [PATCH] more nits --- main.go | 6 +++--- pkg/cache/main.go | 2 +- pkg/output/json.go | 10 +++++----- pkg/output/main.go | 3 ++- pkg/output/text.go | 10 +++++----- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 91ac27d..c102056 100644 --- a/main.go +++ b/main.go @@ -138,9 +138,9 @@ func (ap *arrayParam) Set(value string) error { func getLogger(outputFormat string, printSummary, quiet bool) (output.Output, error) { switch { case outputFormat == "text": - return output.NewTextOutput(printSummary, quiet), nil + return output.Text(printSummary, quiet), nil case outputFormat == "json": - return output.NewJSONOutput(printSummary, quiet), nil + return output.JSON(printSummary, quiet), nil default: return nil, fmt.Errorf("-output must be text or json") } @@ -230,7 +230,7 @@ func realMain() int { } }() - c := cache.NewSchemaCache() + c := cache.New() var wg sync.WaitGroup for i := 0; i < nWorkers; i++ { wg.Add(1) diff --git a/pkg/cache/main.go b/pkg/cache/main.go index f34288a..6b8acd9 100644 --- a/pkg/cache/main.go +++ b/pkg/cache/main.go @@ -11,7 +11,7 @@ type SchemaCache struct { schemas map[string]*gojsonschema.Schema } -func NewSchemaCache() *SchemaCache { +func New() *SchemaCache { return &SchemaCache{ schemas: map[string]*gojsonschema.Schema{}, } diff --git a/pkg/output/json.go b/pkg/output/json.go index 7d04a71..83b3867 100644 --- a/pkg/output/json.go +++ b/pkg/output/json.go @@ -13,15 +13,15 @@ type result struct { Msg string `json:"msg"` } -type JSONOutput struct { +type jsono struct { withSummary bool quiet bool results []result nValid, nInvalid, nErrors, nSkipped int } -func NewJSONOutput(withSummary bool, quiet bool) Output { - return &JSONOutput{ +func JSON(withSummary bool, quiet bool) Output { + return &jsono{ withSummary: withSummary, quiet: quiet, results: []result{}, @@ -32,7 +32,7 @@ func NewJSONOutput(withSummary bool, quiet bool) Output { } } -func (o *JSONOutput) Write(filename, kind, version string, err error, skipped bool) { +func (o *jsono) Write(filename, kind, version string, err error, skipped bool) { msg, st := "", "" s := status(err, skipped) @@ -59,7 +59,7 @@ func (o *JSONOutput) Write(filename, kind, version string, err error, skipped bo } } -func (o *JSONOutput) Flush() { +func (o *jsono) Flush() { var err error var res []byte diff --git a/pkg/output/main.go b/pkg/output/main.go index a1a5ac3..5033bd0 100644 --- a/pkg/output/main.go +++ b/pkg/output/main.go @@ -5,7 +5,8 @@ import ( ) const ( - VALID = iota + _ = iota + VALID INVALID ERROR SKIPPED diff --git a/pkg/output/text.go b/pkg/output/text.go index d3e660a..cb44ffe 100644 --- a/pkg/output/text.go +++ b/pkg/output/text.go @@ -5,15 +5,15 @@ import ( "sync" ) -type TextOutput struct { +type text struct { sync.Mutex withSummary bool quiet bool nValid, nInvalid, nErrors, nSkipped int } -func NewTextOutput(withSummary, quiet bool) Output { - return &TextOutput{ +func Text(withSummary, quiet bool) Output { + return &text{ withSummary: withSummary, quiet: quiet, nValid: 0, @@ -23,7 +23,7 @@ func NewTextOutput(withSummary, quiet bool) Output { } } -func (o *TextOutput) Write(filename, kind, version string, err error, skipped bool) { +func (o *text) Write(filename, kind, version string, err error, skipped bool) { o.Lock() defer o.Unlock() @@ -47,7 +47,7 @@ func (o *TextOutput) Write(filename, kind, version string, err error, skipped bo } } -func (o *TextOutput) Flush() { +func (o *text) Flush() { if o.withSummary { fmt.Printf("Run summary - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", o.nValid, o.nInvalid, o.nErrors, o.nSkipped) }