aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-02 13:59:33 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-02 13:59:33 +0200
commita1d8e1a775496d72a9f033d80ed9ee65a03e6956 (patch)
tree82f40b635f9dfad30830e9aa86a036c72f5fd387 /README.md
parentAdded a section with []byte buffer tricks (diff)
downloadfasthttp-a1d8e1a775496d72a9f033d80ed9ee65a03e6956.tar.gz
fasthttp-a1d8e1a775496d72a9f033d80ed9ee65a03e6956.tar.bz2
fasthttp-a1d8e1a775496d72a9f033d80ed9ee65a03e6956.zip
formatting
Diffstat (limited to 'README.md')
-rw-r--r--README.md24
1 files changed, 21 insertions, 3 deletions
diff --git a/README.md b/README.md
index 8e35244..6e50bd1 100644
--- a/README.md
+++ b/README.md
@@ -308,8 +308,8 @@ code after switching to fasthttp.
The following tricks are used by fasthttp. Use them in your code too.
+* Standard Go functions accept nil buffers
```go
-// Standard Go functions accept nil buffer:
var (
// both buffers are uninitialized
dst []byte
@@ -319,11 +319,29 @@ dst = append(dst, src...) // this is legal code
copy(dst, src) // this is legal code
(string(src) == "") // is true
(len(src) == 0) // is true
+```
+
+So throw away nil checks for []byte buffers from you code. For example,
+```go
+srcLen := 0
+if src != nil {
+ srcLen = len(src)
+}
+```
+
+becomes
-// strings may be appended to []byte buffer with append:
+```go
+srcLen := len(src)
+```
+
+* String may be appended to []byte buffer with append
+```go
dst = append(dst, "foobar"...)
+```
-// All fasthttp functions accept nil []byte buffer:
+* All fasthttp functions accept nil []byte buffer
+```go
statusCode, body, err := fasthttp.Get(nil, "http://google.com/")
uintBuf := fasthttp.AppendUint(nil, 1234)
```