github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/printers/json.go (about) 1 package printers 2 3 import ( 4 "context" 5 "encoding/json" 6 "io" 7 8 "github.com/golangci/golangci-lint/pkg/report" 9 "github.com/golangci/golangci-lint/pkg/result" 10 ) 11 12 type JSON struct { 13 rd *report.Data 14 w io.Writer 15 } 16 17 func NewJSON(rd *report.Data, w io.Writer) *JSON { 18 return &JSON{ 19 rd: rd, 20 w: w, 21 } 22 } 23 24 type JSONResult struct { 25 Issues []result.Issue 26 Report *report.Data 27 } 28 29 func (p JSON) Print(ctx context.Context, issues []result.Issue) error { 30 res := JSONResult{ 31 Issues: issues, 32 Report: p.rd, 33 } 34 if res.Issues == nil { 35 res.Issues = []result.Issue{} 36 } 37 38 return json.NewEncoder(p.w).Encode(res) 39 }