fix recorders

This commit is contained in:
Denis Galeev
2025-04-02 18:47:45 +03:00
committed by ginuerzh
parent 0e59ccc64b
commit 1eaf08c9c1
4 changed files with 79 additions and 20 deletions
+19 -6
View File
@@ -4,24 +4,34 @@ import (
"context"
"io"
"github.com/go-gost/core/metrics"
"github.com/go-gost/core/recorder"
xmetrics "github.com/go-gost/x/metrics"
)
type fileRecorderOptions struct {
sep string
recorder string
sep string
}
type FileRecorderOption func(opts *fileRecorderOptions)
func SepRecorderOption(sep string) FileRecorderOption {
func RecorderFileRecorderOption(recorder string) FileRecorderOption {
return func(opts *fileRecorderOptions) {
opts.recorder = recorder
}
}
func SepFileRecorderOption(sep string) FileRecorderOption {
return func(opts *fileRecorderOptions) {
opts.sep = sep
}
}
type fileRecorder struct {
out io.WriteCloser
sep string
recorder string
out io.WriteCloser
sep string
}
// FileRecorder records data to file.
@@ -32,12 +42,15 @@ func FileRecorder(out io.WriteCloser, opts ...FileRecorderOption) recorder.Recor
}
return &fileRecorder{
out: out,
sep: options.sep,
recorder: options.recorder,
out: out,
sep: options.sep,
}
}
func (r *fileRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error {
xmetrics.GetCounter(xmetrics.MetricRecorderRecordsCounter, metrics.Labels{"recorder": r.recorder}).Inc()
if _, err := r.out.Write(b); err != nil {
return err
}