From f287efd0968cd76e25411348e83f20221b783850 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Sun, 20 Dec 2020 23:04:19 +0300 Subject: [PATCH] Allow specify global service (useful via env vars) --- input_dummy.go | 4 ++-- plugins.go | 6 +++++- settings.go | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/input_dummy.go b/input_dummy.go index e05ccc8..eb27815 100644 --- a/input_dummy.go +++ b/input_dummy.go @@ -6,8 +6,8 @@ import ( // DummyInput used for debugging. It generate 1 "GET /"" request per second. type DummyInput struct { - data chan []byte - quit chan struct{} + data chan []byte + quit chan struct{} Service string } diff --git a/plugins.go b/plugins.go index 168a585..23725d5 100644 --- a/plugins.go +++ b/plugins.go @@ -51,6 +51,10 @@ func extractLimitOptions(options string) (string, string) { // // See this article if curious about reflect stuff below: http://blog.burntsushi.net/type-parametric-functions-golang func (plugins *InOutPlugins) registerPlugin(service string, constructor interface{}, options ...interface{}) { + if service == "" && Settings.Service != "" { + service = Settings.Service + } + var path, limit string vc := reflect.ValueOf(constructor) @@ -71,7 +75,7 @@ func (plugins *InOutPlugins) registerPlugin(service string, constructor interfac // Calling our constructor with list of given options plugin := vc.Call(vo)[0].Interface() fmt.Sprintf("%#v", vc.Call(vo)[0].Interface()) - // reflect.ValueOf(plugin).Elem().FieldByName("Service").SetString(service) + reflect.ValueOf(plugin).Elem().FieldByName("Service").SetString(service) if limit != "" { plugin = NewLimiter(plugin, limit) diff --git a/settings.go b/settings.go index d35076d..37f9770 100644 --- a/settings.go +++ b/settings.go @@ -73,6 +73,7 @@ type ServiceSettings struct { type AppSettings struct { ServiceSettings `mapstructure:",squash"` + Service string `mapstructure:",service"` Services map[string]ServiceSettings `json:"services" mapstructure:"services"` } @@ -98,6 +99,8 @@ func init() { Settings.ExitAfter = 5 * time.Minute } + flag.StringVar(&Settings.Service, "service", "", "Identified of currenlty capture service. Can be used if you need to record and replay mutiple services at once.") + flag.BoolVar(&Settings.SplitOutput, "split-output", false, "By default each output gets same traffic. If set to `true` it splits traffic equally among all outputs.") flag.BoolVar(&Settings.RecognizeTCPSessions, "recognize-tcp-sessions", false, "[PRO] If turned on http output will create separate worker for each TCP session. Splitting output will session based as well.")