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.
This commit is contained in:
Aliaksandr Valialkin
2016-03-04 16:55:39 +02:00
parent 15e46458ea
commit 9fa69c74af
8 changed files with 30 additions and 0 deletions
+2
View File
@@ -39,6 +39,8 @@ type Args struct {
args []argsKV
bufKV argsKV
buf []byte
noCopy
}
type argsKV struct {
+4
View File
@@ -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 {
+2
View File
@@ -55,6 +55,8 @@ type Cookie struct {
bufKV argsKV
buf []byte
noCopy
}
// CopyTo copies src cookie to c.
+4
View File
@@ -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'
+4
View File
@@ -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.
+8
View File
@@ -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() {}
+4
View File
@@ -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.
+2
View File
@@ -50,6 +50,8 @@ type URI struct {
requestURI []byte
h *RequestHeader
noCopy
}
// CopyTo copies uri contents to dst.