Rename input modifier to middleware

This commit is contained in:
Leonid Bugaev
2015-07-09 20:24:27 +05:00
parent 8db14e334d
commit e64aac9364
4 changed files with 13 additions and 13 deletions
+7 -7
View File
@@ -11,7 +11,7 @@ import (
"strings"
)
type TrafficModifier struct {
type Middleware struct {
plugin interface{}
command string
@@ -21,8 +21,8 @@ type TrafficModifier struct {
Stdout io.Reader
}
func NewTrafficModifier(plugin interface{}, command string) io.Reader {
m := new(TrafficModifier)
func NewMiddleware(plugin interface{}, command string) io.Reader {
m := new(Middleware)
m.plugin = plugin
m.command = command
m.data = make(chan []byte)
@@ -50,7 +50,7 @@ func NewTrafficModifier(plugin interface{}, command string) io.Reader {
return m
}
func (m *TrafficModifier) copy(to io.Writer, from io.Reader) {
func (m *Middleware) copy(to io.Writer, from io.Reader) {
buf := make([]byte, 5*1024*1024)
dst := make([]byte, len(buf)*2)
@@ -64,7 +64,7 @@ func (m *TrafficModifier) copy(to io.Writer, from io.Reader) {
}
}
func (m *TrafficModifier) read(from io.Reader) {
func (m *Middleware) read(from io.Reader) {
buf := make([]byte, 5*1024*1024)
scanner := bufio.NewScanner(from)
@@ -85,7 +85,7 @@ func (m *TrafficModifier) read(from io.Reader) {
return
}
func (m *TrafficModifier) Read(data []byte) (int, error) {
func (m *Middleware) Read(data []byte) (int, error) {
Debug("Trying to read channel!")
buf := <-m.data
copy(data, buf)
@@ -93,6 +93,6 @@ func (m *TrafficModifier) Read(data []byte) (int, error) {
return len(buf), nil
}
func (m *TrafficModifier) String() string {
func (m *Middleware) String() string {
return fmt.Sprintf("Modifying traffic for %s using '%s' command", m.plugin, m.command)
}
@@ -82,7 +82,7 @@ func TestFakeSecureService(t *testing.T) {
wg.Wait()
}
func TestTrafficModifier(t *testing.T) {
func TestMiddleware(t *testing.T) {
var resp *http.Response
wg := new(sync.WaitGroup)
+3 -3
View File
@@ -10,7 +10,7 @@ type InOutPlugins struct {
Inputs []io.Reader
Outputs []io.Writer
Modifiers []TrafficModifier
Middleware []Middleware
}
type ReaderOrWriter interface{}
@@ -56,8 +56,8 @@ func registerPlugin(constructor interface{}, options ...interface{}) {
}
if _, ok := plugin.(io.Reader); ok {
for _, options := range Settings.inputModifier {
plugin_wrapper = NewTrafficModifier(plugin_wrapper, options)
for _, options := range Settings.middleware {
plugin_wrapper = NewMiddleware(plugin_wrapper, options)
}
Plugins.Inputs = append(Plugins.Inputs, plugin_wrapper.(io.Reader))
}
+2 -2
View File
@@ -41,7 +41,7 @@ type AppSettings struct {
inputRAW MultiOption
inputModifier MultiOption
middleware MultiOption
inputHTTP MultiOption
outputHTTP MultiOption
@@ -78,7 +78,7 @@ func init() {
flag.Var(&Settings.inputRAW, "input-raw", "Capture traffic from given port (use RAW sockets and require *sudo* access):\n\t# Capture traffic from 8080 port\n\tgor --input-raw :8080 --output-http staging.com")
flag.Var(&Settings.inputModifier, "input-modifier", "Used for modifying input traffic using external command")
flag.Var(&Settings.middleware, "middleware", "Used for modifying input traffic using external command")
flag.Var(&Settings.inputHTTP, "input-http", "Read requests from HTTP, should be explicitly sent from your application:\n\t# Listen for http on 9000\n\tgor --input-http :9000 --output-http staging.com")