fix recorders
This commit is contained in:
+19
-6
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user