| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package govulncheck |
| 8 |
|
| 9 |
import ( |
| 10 |
"encoding/json" |
| 11 |
|
| 12 |
"io" |
| 13 |
|
| 14 |
"golang.org/x/tools/gopls/internal/vulncheck/osv" |
| 15 |
) |
| 16 |
|
| 17 |
type jsonHandler struct { |
| 18 |
enc *json.Encoder |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
func NewJSONHandler(w io.Writer) Handler { |
| 23 |
enc := json.NewEncoder(w) |
| 24 |
enc.SetIndent("", " ") |
| 25 |
return &jsonHandler{enc: enc} |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
func (h *jsonHandler) Config(config *Config) error { |
| 30 |
return h.enc.Encode(Message{Config: config}) |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
func (h *jsonHandler) Progress(progress *Progress) error { |
| 35 |
return h.enc.Encode(Message{Progress: progress}) |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
func (h *jsonHandler) OSV(entry *osv.Entry) error { |
| 40 |
return h.enc.Encode(Message{OSV: entry}) |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
func (h *jsonHandler) Finding(finding *Finding) error { |
| 45 |
return h.enc.Encode(Message{Finding: finding}) |
| 46 |
} |