Unify all input/output plugins

This commit is contained in:
Leonid Bugaev
2015-08-18 14:32:52 +03:00
parent ea94dd0162
commit 3e763c43cf
17 changed files with 136 additions and 106 deletions
+2 -1
View File
@@ -22,7 +22,6 @@ while read line; do
case ${header:0:1} in
"1")
log "Request type: Request"
echo "$encoded"
;;
"2")
log "Request type: Original Response"
@@ -33,6 +32,8 @@ while read line; do
*)
log "Unknown request type $header"
esac
echo "$encoded"
log "==================================="
log "Original data: $line"
+11 -11
View File
@@ -80,21 +80,13 @@ func process(buf []byte) {
payload = proto.SetPathParam(payload, []byte("token"), alias)
// Copy modified payload to our buffer
copy(buf[headerSize:], payload)
buf = append(buf[:headerSize], payload...)
}
}
}
// Re-compute length in case if payload was modified
bufLen := headerSize + len(payload)
// Encoding request and sending it back
dst := make([]byte, bufLen*2+1)
hex.Encode(dst, buf[:bufLen])
dst[len(dst)-1] = '\n'
os.Stdout.Write(dst)
return
// Emitting data back
os.Stdout.Write(encode(buf))
case '2': // Original response
if _, ok := originalTokens[reqID]; ok {
// Token is inside response body
@@ -113,6 +105,14 @@ func process(buf []byte) {
}
}
func encode(buf []byte) []byte {
dst := make([]byte, len(buf)*2+1)
hex.Encode(dst, buf)
dst[len(dst)-1] = '\n'
return dst
}
func Debug(args ...interface{}) {
fmt.Fprint(os.Stderr, "[DEBUG][TOKEN-MOD] ")
fmt.Fprintln(os.Stderr, args...)