From e0871842d29ea36a23b2d4ca8528740978ac4a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20M=C3=BCrk?= Date: Wed, 15 Feb 2023 19:35:38 +0200 Subject: [PATCH] the code --- .gitignore | 2 ++ cmd/main.go | 39 +++++++++++++++++++++++++++++++++++++++ go.mod | 11 +++++++++++ go.sum | 22 ++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7aa03e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +bin/* \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..155ac6d --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "github.com/valyala/fasthttp" + "log" +) + +func main() { + if err := fasthttp.ListenAndServe(":8080", requestHandler); err != nil { + log.Fatalf("Error in ListenAndServe: %v", err) + } +} + +func requestHandler(ctx *fasthttp.RequestCtx) { + fmt.Fprintf(ctx, "Hello, world!\n\n") + + fmt.Fprintf(ctx, "Request method is %q\n", ctx.Method()) + fmt.Fprintf(ctx, "RequestURI is %q\n", ctx.RequestURI()) + fmt.Fprintf(ctx, "Requested path is %q\n", ctx.Path()) + fmt.Fprintf(ctx, "Host is %q\n", ctx.Host()) + fmt.Fprintf(ctx, "Query string is %q\n", ctx.QueryArgs()) + fmt.Fprintf(ctx, "User-Agent is %q\n", ctx.UserAgent()) + fmt.Fprintf(ctx, "Connection has been established at %s\n", ctx.ConnTime()) + fmt.Fprintf(ctx, "Request has been started at %s\n", ctx.Time()) + fmt.Fprintf(ctx, "Serial request number for the current connection is %d\n", ctx.ConnRequestNum()) + fmt.Fprintf(ctx, "Your ip is %q\n\n", ctx.RemoteIP()) + + fmt.Fprintf(ctx, "Raw request is:\n---CUT---\n%s\n---CUT---", &ctx.Request) + + ctx.SetContentType("text/plain; charset=utf8") + + ctx.Response.Header.Set("X-My-Header", "my-header-value") + + var c fasthttp.Cookie + c.SetKey("cookie-name") + c.SetValue("cookie-value") + ctx.Response.Header.SetCookie(&c) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..61e9446 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module demosite + +go 1.19 + +require github.com/valyala/fasthttp v1.44.0 + +require ( + github.com/andybalholm/brotli v1.0.4 // indirect + github.com/klauspost/compress v1.15.15 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f70e873 --- /dev/null +++ b/go.sum @@ -0,0 +1,22 @@ +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= +github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= +github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.44.0 h1:R+gLUhldIsfg1HokMuQjdQ5bh9nuXHPIfvkYUu9eR5Q= +github.com/valyala/fasthttp v1.44.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=