add traffic reset for stats

This commit is contained in:
ginuerzh
2024-12-24 20:11:22 +08:00
parent 914a4622fd
commit 06d993023f
41 changed files with 407 additions and 143 deletions
+5 -1
View File
@@ -3,6 +3,7 @@ package recorder
import (
"context"
"encoding/json"
"errors"
"io"
"github.com/go-gost/core/logger"
@@ -56,7 +57,7 @@ func (p *grpcPlugin) Record(ctx context.Context, b []byte, opts ...recorder.Reco
md, _ := json.Marshal(options.Metadata)
_, err := p.client.Record(ctx,
reply, err := p.client.Record(ctx,
&proto.RecordRequest{
Data: b,
Metadata: md,
@@ -65,6 +66,9 @@ func (p *grpcPlugin) Record(ctx context.Context, b []byte, opts ...recorder.Reco
p.log.Error(err)
return err
}
if reply == nil || !reply.Ok {
return errors.New("record failed")
}
return nil
}
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/go-gost/core/logger"
@@ -84,7 +83,7 @@ func (p *httpPlugin) Record(ctx context.Context, b []byte, opts ...recorder.Reco
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s", resp.Status)
return errors.New(resp.Status)
}
res := httpPluginResponse{}