Debian Codegraph @

gopls/internal/vulncheck/govulncheck/jsonhandler.go

raw symbols SCIP
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Code generated by copying from golang.org/x/[email protected] (go run copier.go); DO NOT EDIT.
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 // NewJSONHandler returns a handler that writes govulncheck output as json.
22 func NewJSONHandler(w io.Writer) Handler {
23 enc := json.NewEncoder(w)
24 enc.SetIndent("", " ")
25 return &jsonHandler{enc: enc}
26 }
27
28 // Config writes config block in JSON to the underlying writer.
29 func (h *jsonHandler) Config(config *Config) error {
30 return h.enc.Encode(Message{Config: config})
31 }
32
33 // Progress writes a progress message in JSON to the underlying writer.
34 func (h *jsonHandler) Progress(progress *Progress) error {
35 return h.enc.Encode(Message{Progress: progress})
36 }
37
38 // OSV writes an osv entry in JSON to the underlying writer.
39 func (h *jsonHandler) OSV(entry *osv.Entry) error {
40 return h.enc.Encode(Message{OSV: entry})
41 }
42
43 // Finding writes a finding in JSON to the underlying writer.
44 func (h *jsonHandler) Finding(finding *Finding) error {
45 return h.enc.Encode(Message{Finding: finding})
46 }