add handler recorder
This commit is contained in:
+3
-2
@@ -284,8 +284,9 @@ type TCPRecorder struct {
|
||||
}
|
||||
|
||||
type HTTPRecorder struct {
|
||||
URL string `json:"url" yaml:"url"`
|
||||
Timeout time.Duration `json:"timeout"`
|
||||
URL string `yaml:"url" json:"url"`
|
||||
Timeout time.Duration `yaml:",omitempty" json:"timeout,omitempty"`
|
||||
Header map[string]string `yaml:",omitempty" json:"header,omitempty"`
|
||||
}
|
||||
|
||||
type RedisRecorder struct {
|
||||
|
||||
@@ -2,6 +2,7 @@ package recorder
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-gost/core/recorder"
|
||||
@@ -51,7 +52,14 @@ func ParseRecorder(cfg *config.RecorderConfig) (r recorder.Recorder) {
|
||||
}
|
||||
|
||||
if cfg.HTTP != nil && cfg.HTTP.URL != "" {
|
||||
return xrecorder.HTTPRecorder(cfg.HTTP.URL, xrecorder.TimeoutHTTPRecorderOption(cfg.HTTP.Timeout))
|
||||
h := http.Header{}
|
||||
for k, v := range cfg.HTTP.Header {
|
||||
h.Add(k, v)
|
||||
}
|
||||
return xrecorder.HTTPRecorder(cfg.HTTP.URL,
|
||||
xrecorder.TimeoutHTTPRecorderOption(cfg.HTTP.Timeout),
|
||||
xrecorder.HeaderHTTPRecorderOption(h),
|
||||
)
|
||||
}
|
||||
|
||||
if cfg.Redis != nil &&
|
||||
|
||||
@@ -278,6 +278,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
||||
handler.RateLimiterOption(registry.RateLimiterRegistry().Get(cfg.RLimiter)),
|
||||
handler.TrafficLimiterOption(registry.TrafficLimiterRegistry().Get(cfg.Handler.Limiter)),
|
||||
handler.ObserverOption(registry.ObserverRegistry().Get(cfg.Handler.Observer)),
|
||||
handler.RecordersOption(recorders...),
|
||||
handler.LoggerOption(handlerLogger),
|
||||
handler.ServiceOption(cfg.Name),
|
||||
handler.NetnsOption(netnsIn),
|
||||
|
||||
Reference in New Issue
Block a user