more nits

This commit is contained in:
Yann Hamon 2020-06-01 12:44:59 +02:00
parent 5ff2d1a037
commit 0ddf4e9a50
5 changed files with 16 additions and 15 deletions

View file

@ -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)

2
pkg/cache/main.go vendored
View file

@ -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{},
}

View file

@ -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

View file

@ -5,7 +5,8 @@ import (
)
const (
VALID = iota
_ = iota
VALID
INVALID
ERROR
SKIPPED

View file

@ -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)
}