From 9fa69c74af439f4e92e525a8bdde7be4e1ee6435 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 4 Mar 2016 16:55:39 +0200 Subject: [PATCH] Embed noCopy struct into structs, which mustn't be copied This should help `go vet` detecting invalid structs' copyings. See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. --- args.go | 2 ++ client.go | 4 ++++ cookie.go | 2 ++ header.go | 4 ++++ http.go | 4 ++++ nocopy.go | 8 ++++++++ server.go | 4 ++++ uri.go | 2 ++ 8 files changed, 30 insertions(+) create mode 100644 nocopy.go diff --git a/args.go b/args.go index 92f8e4c..28bcb2e 100644 --- a/args.go +++ b/args.go @@ -39,6 +39,8 @@ type Args struct { args []argsKV bufKV argsKV buf []byte + + noCopy } type argsKV struct { diff --git a/client.go b/client.go index b48e9fa..cdf55cc 100644 --- a/client.go +++ b/client.go @@ -201,6 +201,8 @@ type Client struct { mLock sync.Mutex m map[string]*HostClient ms map[string]*HostClient + + noCopy } // Get appends url contents to dst and returns it as body. @@ -511,6 +513,8 @@ type HostClient struct { readerPool sync.Pool writerPool sync.Pool + + noCopy } type clientConn struct { diff --git a/cookie.go b/cookie.go index c04e70f..9613142 100644 --- a/cookie.go +++ b/cookie.go @@ -55,6 +55,8 @@ type Cookie struct { bufKV argsKV buf []byte + + noCopy } // CopyTo copies src cookie to c. diff --git a/header.go b/header.go index 6659911..7543d09 100644 --- a/header.go +++ b/header.go @@ -33,6 +33,8 @@ type ResponseHeader struct { bufKV argsKV cookies []argsKV + + noCopy } // RequestHeader represents HTTP request header. @@ -68,6 +70,8 @@ type RequestHeader struct { cookies []argsKV rawHeaders []byte + + noCopy } // SetContentRange sets 'Content-Range: bytes startPos-endPos/contentLength' diff --git a/http.go b/http.go index 7724e9a..b7a34fe 100644 --- a/http.go +++ b/http.go @@ -37,6 +37,8 @@ type Request struct { // Group bool members in order to reduce Request object size. parsedURI bool parsedPostArgs bool + + noCopy } // Response represents HTTP response. @@ -62,6 +64,8 @@ type Response struct { // Response.Write() skips writing body if set to true. // Use it for writing HEAD responses. SkipBody bool + + noCopy } // SetRequestURI sets RequestURI. diff --git a/nocopy.go b/nocopy.go new file mode 100644 index 0000000..c9ca4e9 --- /dev/null +++ b/nocopy.go @@ -0,0 +1,8 @@ +package fasthttp + +// Embed this type into a struct, which mustn't be copied, +// so `go vet` gives a warning if this struct is copied. +// +// See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. +type noCopy struct {} +func (*noCopy) Lock() {} diff --git a/server.go b/server.go index 33f287a..910fa6f 100644 --- a/server.go +++ b/server.go @@ -270,6 +270,8 @@ type Server struct { writerPool sync.Pool hijackConnPool sync.Pool bytePool sync.Pool + + noCopy } // TimeoutHandler creates RequestHandler, which returns StatusRequestTimeout @@ -374,6 +376,8 @@ type RequestCtx struct { timeoutTimer *time.Timer hijackHandler HijackHandler + + noCopy } // HijackHandler must process the hijacked connection c. diff --git a/uri.go b/uri.go index a0e2744..a7b50d3 100644 --- a/uri.go +++ b/uri.go @@ -50,6 +50,8 @@ type URI struct { requestURI []byte h *RequestHeader + + noCopy } // CopyTo copies uri contents to dst.