aboutsummaryrefslogtreecommitdiff
path: root/reuseport
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-05-10 14:58:07 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-05-10 14:58:07 +0300
commitf43cd21abb7f172f9ca0e967ecca7452b61242d9 (patch)
tree6985b9d81fc776fbbef3c0bbfc04a9a96ae7b735 /reuseport
parentreuseport: close Listener in case of error (#94) (diff)
downloadfasthttp-f43cd21abb7f172f9ca0e967ecca7452b61242d9.tar.gz
fasthttp-f43cd21abb7f172f9ca0e967ecca7452b61242d9.tar.bz2
fasthttp-f43cd21abb7f172f9ca0e967ecca7452b61242d9.zip
Issue #93: added an example for reuseport.Listener
Diffstat (limited to 'reuseport')
-rw-r--r--reuseport/reuseport_example_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/reuseport/reuseport_example_test.go b/reuseport/reuseport_example_test.go
new file mode 100644
index 0000000..03a7ac9
--- /dev/null
+++ b/reuseport/reuseport_example_test.go
@@ -0,0 +1,24 @@
+package reuseport_test
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/valyala/fasthttp"
+ "github.com/valyala/fasthttp/reuseport"
+)
+
+func ExampleListener() {
+ ln, err := reuseport.Listen("tcp4", "localhost:12345")
+ if err != nil {
+ log.Fatalf("error in reuseport listener: %s", err)
+ }
+
+ if err = fasthttp.Serve(ln, requestHandler); err != nil {
+ log.Fatalf("error in fasthttp Server: %s", err)
+ }
+}
+
+func requestHandler(ctx *fasthttp.RequestCtx) {
+ fmt.Fprintf(ctx, "Hello, world!")
+}