mirror of
https://github.com/kopia/kopia.git
synced 2026-05-11 08:16:12 -04:00
Remove unused-parameter exclusion for `ctx` in revive linter. --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
// Package jsonsender provides a notification sender that writes messages in JSON format to the provided writer.
|
|
package jsonsender
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/notification/sender"
|
|
)
|
|
|
|
type jsonSender struct {
|
|
prefix string
|
|
out io.Writer
|
|
minSeverity sender.Severity
|
|
}
|
|
|
|
func (p *jsonSender) Send(_ context.Context, msg *sender.Message) error {
|
|
if msg.Severity < p.minSeverity {
|
|
return nil
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
|
|
buf.WriteString(p.prefix)
|
|
|
|
if err := json.NewEncoder(&buf).Encode(msg); err != nil {
|
|
return errors.Wrap(err, "unable to encode JSON")
|
|
}
|
|
|
|
_, err := p.out.Write(buf.Bytes())
|
|
|
|
return err //nolint:wrapcheck
|
|
}
|
|
|
|
func (p *jsonSender) Summary() string {
|
|
return "JSON sender"
|
|
}
|
|
|
|
func (p *jsonSender) Format() string {
|
|
return sender.FormatPlainText
|
|
}
|
|
|
|
func (p *jsonSender) ProfileName() string {
|
|
return "jsonsender"
|
|
}
|
|
|
|
// NewJSONSender creates a new JSON sender that writes messages to the provided writer.
|
|
func NewJSONSender(prefix string, out io.Writer, minSeverity sender.Severity) sender.Sender {
|
|
return &jsonSender{
|
|
prefix: prefix,
|
|
out: out,
|
|
minSeverity: minSeverity,
|
|
}
|
|
}
|