From 63b166f257675529007b73ab5f2cc0d8864182af Mon Sep 17 00:00:00 2001 From: ia Date: Sat, 16 Jun 2018 23:21:00 +0200 Subject: [PATCH] all: gofmt Run standard gofmt command on project root. - go version go1.10.3 darwin/amd64 --- ext/html/html.go | 2 +- ext/image/image.go | 4 ++-- proxy_test.go | 14 +++++++------- regretable/regretreader.go | 6 +++--- regretable/regretreader_test.go | 6 +++--- transport/roundtripper.go | 2 ++ transport/transport.go | 24 ++++++++++++------------ 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ext/html/html.go b/ext/html/html.go index e8397aa4..2dc294ec 100644 --- a/ext/html/html.go +++ b/ext/html/html.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" + "github.com/elazarl/goproxy" "github.com/rogpeppe/go-charset/charset" _ "github.com/rogpeppe/go-charset/data" - "github.com/elazarl/goproxy" ) var IsHtml goproxy.RespCondition = goproxy.ContentTypeIs("text/html") diff --git a/ext/image/image.go b/ext/image/image.go index 3dc26ff3..cd9ac8a4 100644 --- a/ext/image/image.go +++ b/ext/image/image.go @@ -2,14 +2,14 @@ package goproxy_image import ( "bytes" + . "github.com/elazarl/goproxy" + "github.com/elazarl/goproxy/regretable" "image" _ "image/gif" "image/jpeg" "image/png" "io/ioutil" "net/http" - . "github.com/elazarl/goproxy" - "github.com/elazarl/goproxy/regretable" ) var RespIsImage = ContentTypeIs("image/gif", diff --git a/proxy_test.go b/proxy_test.go index 45c57552..8117517f 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -666,13 +666,13 @@ func TestGoproxyHijackConnect(t *testing.T) { proxy := goproxy.NewProxyHttpServer() proxy.OnRequest(goproxy.ReqHostIs(srv.Listener.Addr().String())). HijackConnect(func(req *http.Request, client net.Conn, ctx *goproxy.ProxyCtx) { - t.Logf("URL %+#v\nSTR %s", req.URL, req.URL.String()) - resp, err := http.Get("http:" + req.URL.String() + "/bobo") - panicOnErr(err, "http.Get(CONNECT url)") - panicOnErr(resp.Write(client), "resp.Write(client)") - resp.Body.Close() - client.Close() - }) + t.Logf("URL %+#v\nSTR %s", req.URL, req.URL.String()) + resp, err := http.Get("http:" + req.URL.String() + "/bobo") + panicOnErr(err, "http.Get(CONNECT url)") + panicOnErr(resp.Write(client), "resp.Write(client)") + resp.Body.Close() + client.Close() + }) client, l := oneShotProxy(proxy, t) defer l.Close() proxyAddr := l.Listener.Addr().String() diff --git a/regretable/regretreader.go b/regretable/regretreader.go index 1458af58..29b60add 100644 --- a/regretable/regretreader.go +++ b/regretable/regretreader.go @@ -24,7 +24,7 @@ var defaultBufferSize = 500 // Same as RegretableReader, but allows closing the underlying reader type RegretableReaderCloser struct { RegretableReader - c io.Closer + c io.Closer } // Closes the underlying readCloser, you cannot regret after closing the stream @@ -69,7 +69,7 @@ func (rb *RegretableReader) Forget() { // initialize a RegretableReader with underlying reader r, whose buffer is size bytes long func NewRegretableReaderSize(r io.Reader, size int) *RegretableReader { - return &RegretableReader{reader: r, buf: make([]byte, size) } + return &RegretableReader{reader: r, buf: make([]byte, size)} } // initialize a RegretableReader with underlying reader r @@ -89,7 +89,7 @@ func (rb *RegretableReader) Read(p []byte) (n int, err error) { } n, err = rb.reader.Read(p) bn := copy(rb.buf[rb.w:], p[:n]) - rb.w, rb.r = rb.w + bn, rb.w + n + rb.w, rb.r = rb.w+bn, rb.w+n if bn < n { rb.overflow = true } diff --git a/regretable/regretreader_test.go b/regretable/regretreader_test.go index 55fa752b..55969747 100644 --- a/regretable/regretreader_test.go +++ b/regretable/regretreader_test.go @@ -1,8 +1,8 @@ package regretable_test import ( - . "github.com/elazarl/goproxy/regretable" "bytes" + . "github.com/elazarl/goproxy/regretable" "io" "io/ioutil" "strings" @@ -94,14 +94,14 @@ func TestRegretableFullRead(t *testing.T) { } func assertEqual(t *testing.T, expected, actual string) { - if expected!=actual { + if expected != actual { t.Fatal("Expected", expected, "actual", actual) } } func assertReadAll(t *testing.T, r io.Reader) string { s, err := ioutil.ReadAll(r) - if err!=nil { + if err != nil { t.Fatal("error when reading", err) } return string(s) diff --git a/transport/roundtripper.go b/transport/roundtripper.go index 3651ad86..d070a213 100644 --- a/transport/roundtripper.go +++ b/transport/roundtripper.go @@ -1,5 +1,7 @@ package transport + import "net/http" + type RoundTripper interface { // RoundTrip executes a single HTTP transaction, returning // the Response for the request req. RoundTrip should not diff --git a/transport/transport.go b/transport/transport.go index fc1c82b1..c943bd68 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // HTTP client implementation. See RFC 2616. -// +// // This is the low-level Transport implementation of RoundTripper. // The high-level interface is in client.go. @@ -12,7 +12,6 @@ package transport import ( - "net/http" "bufio" "compress/gzip" "crypto/tls" @@ -23,6 +22,7 @@ import ( "io/ioutil" "log" "net" + "net/http" "net/url" "os" "strings" @@ -114,8 +114,8 @@ func ProxyURL(fixedURL *url.URL) func(*http.Request) (*url.URL, error) { // transportRequest is a wrapper around a *Request that adds // optional extra headers to write. type transportRequest struct { - *http.Request // original request, not to be mutated - extra http.Header // extra headers to write, or nil + *http.Request // original request, not to be mutated + extra http.Header // extra headers to write, or nil } func (tr *transportRequest) extraHeaders() http.Header { @@ -126,10 +126,10 @@ func (tr *transportRequest) extraHeaders() http.Header { } type RoundTripDetails struct { - Host string + Host string TCPAddr *net.TCPAddr IsProxy bool - Error error + Error error } func (t *Transport) DetailedRoundTrip(req *http.Request) (details *RoundTripDetails, resp *http.Response, err error) { @@ -311,7 +311,7 @@ func (t *Transport) getIdleConn(cm *connectMethod) (pconn *persistConn) { func (t *Transport) dial(network, addr string) (c net.Conn, raddr string, ip *net.TCPAddr, err error) { if t.Dial != nil { ip, err = net.ResolveTCPAddr("tcp", addr) - if err!=nil { + if err != nil { return } c, err = t.Dial(network, addr) @@ -319,7 +319,7 @@ func (t *Transport) dial(network, addr string) (c net.Conn, raddr string, ip *ne return } addri, err := net.ResolveTCPAddr("tcp", addr) - if err!=nil { + if err != nil { return } c, err = net.DialTCP("tcp", nil, addri) @@ -352,8 +352,8 @@ func (t *Transport) getConn(cm *connectMethod) (*persistConn, error) { cacheKey: cm.String(), conn: conn, reqch: make(chan requestAndChan, 50), - host: raddr, - ip: ip, + host: raddr, + ip: ip, } switch { @@ -526,7 +526,7 @@ type persistConn struct { broken bool // an error has happened on this connection; marked broken so it's not reused. host string - ip *net.TCPAddr + ip *net.TCPAddr } func (pc *persistConn) isBroken() bool { @@ -664,7 +664,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *http.Response, er // requested it. requestedGzip := false if !pc.t.DisableCompression && req.Header.Get("Accept-Encoding") == "" { - // Request gzip only, not deflate. Deflate is ambiguous and + // Request gzip only, not deflate. Deflate is ambiguous and // not as universally supported anyway. // See: http://www.gzip.org/zlib/zlib_faq.html#faq38 requestedGzip = true