Allow specify global service (useful via env vars)

This commit is contained in:
Leonid Bugaev
2020-12-22 17:38:24 +03:00
parent 663f758a71
commit f287efd096
3 changed files with 10 additions and 3 deletions
+2 -2
View File
@@ -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
}
+5 -1
View File
@@ -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)
+3
View File
@@ -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.")