From 3c3661ae6d16f8449aab2f0e2f623ba4874b4832 Mon Sep 17 00:00:00 2001 From: Henrique Vicente Date: Sun, 13 Jun 2021 14:46:49 +0200 Subject: [PATCH] Add Stream function to pgmockproxy.Proxy to print wire protocol representation to any writer. --- pgmockproxy/proxy/proxy.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pgmockproxy/proxy/proxy.go b/pgmockproxy/proxy/proxy.go index 4b498ec..1278fe3 100644 --- a/pgmockproxy/proxy/proxy.go +++ b/pgmockproxy/proxy/proxy.go @@ -3,7 +3,9 @@ package proxy import ( "encoding/json" "fmt" + "io" "net" + "os" "github.com/jackc/pgproto3/v2" ) @@ -32,6 +34,11 @@ func NewProxy(frontendConn, backendConn net.Conn) *Proxy { } func (p *Proxy) Run() error { + return p.Stream(os.Stdout) +} + +// Stream representation of the wire protocol to writer. +func (p *Proxy) Stream(w io.Writer) error { defer p.Close() frontendErrChan := make(chan error, 1) @@ -51,7 +58,7 @@ func (p *Proxy) Run() error { if err != nil { return err } - fmt.Println("F", string(buf)) + fmt.Fprintln(w, "F", string(buf)) err = p.frontend.Send(msg) if err != nil { @@ -63,7 +70,7 @@ func (p *Proxy) Run() error { if err != nil { return err } - fmt.Println("B", string(buf)) + fmt.Fprintln(w, "B", string(buf)) err = p.backend.Send(msg) if err != nil {