add recorder
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
"github.com/go-gost/core/chain"
|
||||
"github.com/go-gost/core/hosts"
|
||||
"github.com/go-gost/core/logger"
|
||||
"github.com/go-gost/core/recorder"
|
||||
"github.com/go-gost/core/resolver"
|
||||
admission_impl "github.com/go-gost/x/admission"
|
||||
auth_impl "github.com/go-gost/x/auth"
|
||||
@ -17,6 +18,7 @@ import (
|
||||
"github.com/go-gost/x/config"
|
||||
hosts_impl "github.com/go-gost/x/hosts"
|
||||
"github.com/go-gost/x/internal/loader"
|
||||
recorder_impl "github.com/go-gost/x/recorder"
|
||||
"github.com/go-gost/x/registry"
|
||||
resolver_impl "github.com/go-gost/x/resolver"
|
||||
)
|
||||
@ -211,3 +213,35 @@ func ParseHosts(cfg *config.HostsConfig) hosts.HostMapper {
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
func ParseRecorder(cfg *config.RecorderConfig) (r recorder.Recorder) {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if cfg.File != nil && cfg.File.Path != "" {
|
||||
return recorder_impl.FileRecorder(cfg.File.Path,
|
||||
recorder_impl.SepRecorderOption(cfg.File.Sep))
|
||||
}
|
||||
|
||||
if cfg.Redis != nil &&
|
||||
cfg.Redis.Addr != "" &&
|
||||
cfg.Redis.Key != "" {
|
||||
switch cfg.Redis.Type {
|
||||
case "list": // redis list
|
||||
return recorder_impl.RedisListRecorder(cfg.Redis.Addr,
|
||||
recorder_impl.DBRedisRecorderOption(cfg.Redis.DB),
|
||||
recorder_impl.KeyRedisRecorderOption(cfg.Redis.Key),
|
||||
recorder_impl.PasswordRedisRecorderOption(cfg.Redis.Password),
|
||||
)
|
||||
default: // redis set
|
||||
return recorder_impl.RedisSetRecorder(cfg.Redis.Addr,
|
||||
recorder_impl.DBRedisRecorderOption(cfg.Redis.DB),
|
||||
recorder_impl.KeyRedisRecorderOption(cfg.Redis.Key),
|
||||
recorder_impl.PasswordRedisRecorderOption(cfg.Redis.Password),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/go-gost/core/handler"
|
||||
"github.com/go-gost/core/listener"
|
||||
"github.com/go-gost/core/logger"
|
||||
"github.com/go-gost/core/recorder"
|
||||
"github.com/go-gost/core/service"
|
||||
"github.com/go-gost/x/config"
|
||||
tls_util "github.com/go-gost/x/internal/util/tls"
|
||||
@ -104,6 +105,13 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
||||
}
|
||||
}
|
||||
|
||||
var recorders []recorder.RecorderObject
|
||||
for _, r := range cfg.Recorders {
|
||||
recorders = append(recorders, recorder.RecorderObject{
|
||||
Recorder: registry.RecorderRegistry().Get(r.Name),
|
||||
Record: r.Record,
|
||||
})
|
||||
}
|
||||
router := (&chain.Router{}).
|
||||
WithRetries(cfg.Handler.Retries).
|
||||
// WithTimeout(timeout time.Duration).
|
||||
@ -112,6 +120,7 @@ func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
|
||||
WithChain(registry.ChainRegistry().Get(cfg.Handler.Chain)).
|
||||
WithResolver(registry.ResolverRegistry().Get(cfg.Resolver)).
|
||||
WithHosts(registry.HostsRegistry().Get(cfg.Hosts)).
|
||||
WithRecorder(recorders...).
|
||||
WithLogger(handlerLogger)
|
||||
|
||||
h := registry.HandlerRegistry().Get(cfg.Handler.Type)(
|
||||
|
Reference in New Issue
Block a user