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
+14 -2
View File
@@ -8,16 +8,25 @@ import (
"strings"
"time"
"github.com/go-gost/core/metrics"
"github.com/go-gost/core/recorder"
xmetrics "github.com/go-gost/x/metrics"
)
type httpRecorderOptions struct {
timeout time.Duration
header http.Header
recorder string
timeout time.Duration
header http.Header
}
type HTTPRecorderOption func(opts *httpRecorderOptions)
func RecorderHTTPRecorderOption(recorder string) HTTPRecorderOption {
return func(opts *httpRecorderOptions) {
opts.recorder = recorder
}
}
func TimeoutHTTPRecorderOption(timeout time.Duration) HTTPRecorderOption {
return func(opts *httpRecorderOptions) {
opts.timeout = timeout
@@ -31,6 +40,7 @@ func HeaderHTTPRecorderOption(header http.Header) HTTPRecorderOption {
}
type httpRecorder struct {
recorder string
url string
httpClient *http.Client
header http.Header
@@ -60,6 +70,8 @@ func HTTPRecorder(url string, opts ...HTTPRecorderOption) recorder.Recorder {
}
func (r *httpRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error {
xmetrics.GetCounter(xmetrics.MetricRecorderRecordsCounter, metrics.Labels{"recorder": r.recorder}).Inc()
req, err := http.NewRequest(http.MethodPost, r.url, bytes.NewReader(b))
if err != nil {
return err