From 36e21902461528f8e31cf8adacefc293a5656221 Mon Sep 17 00:00:00 2001 From: hgouchet Date: Mon, 4 Mar 2019 23:38:23 +0100 Subject: [PATCH] adds start sample --- .gitignore | 3 ++- example/start/start.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 example/start/start.go diff --git a/.gitignore b/.gitignore index b16c99f..1285731 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea -example/server/server example/client/client +example/server/server +example/start/start \ No newline at end of file diff --git a/example/start/start.go b/example/start/start.go new file mode 100644 index 0000000..75a8089 --- /dev/null +++ b/example/start/start.go @@ -0,0 +1,26 @@ +package main + +import ( + "log" + + "github.com/rvflash/tcp" +) + +func main() { + // creates a server with a logger and a recover on panic as middlewares. + r := tcp.Default() + r.ACK(func(c *tcp.Context) { + // new message received + // gets the request body + buf, err := c.ReadAll() + if err != nil { + c.Error(err) + } + // writes something as response + c.String(string(buf)) + }) + err := r.Run(":9090") // listen and serve on 0.0.0.0:9090 + if err != nil { + log.Fatalf("listen: %s", err) + } +}