From ec1ba416bfc3924aad8de8bfe0732832b3637885 Mon Sep 17 00:00:00 2001 From: Fenny Date: Fri, 31 Jan 2020 15:41:01 -0500 Subject: [PATCH] Add JsonString & JsonBytes + Update benchmark links --- application.go | 2 +- docs/benchmarks.md | 16 ++++++++-------- docs/context.md | 30 ++++++++++++++++++++++++++++++ docs/index.html | 2 +- response.go | 12 ++++++++++++ 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/application.go b/application.go index b21d630d..72f54087 100644 --- a/application.go +++ b/application.go @@ -13,7 +13,7 @@ import ( ) const ( - Version = "1.2.2" + Version = "1.2.3" // https://play.golang.org/p/r6GNeV1gbH banner = "" + " \x1b[1;32m _____ _ _\n" + diff --git a/docs/benchmarks.md b/docs/benchmarks.md index 88865f1f..b0b151fa 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -9,26 +9,26 @@ Below you can see the results of tested go frameworks responding in plaintext. -To view the list yourself, [Plaintext Go Results](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext&l=zijocf-1r). -To see all language frameworks, [Plaintext All Results](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext). +To view the list yourself, [Plaintext Go Results](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext&l=zijocf-1r). +To see all language frameworks, [Plaintext All Results](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext). Plaintext -[![](static/benchmarks/techempower-plaintext.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext&l=zijocf-1r) +[![](static/benchmarks/techempower-plaintext.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext&l=zijocf-1r) Plaintext latency -[![](static/benchmarks/techempower-plaintext-latency.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext&l=zijocf-1r) +[![](static/benchmarks/techempower-plaintext-latency.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext&l=zijocf-1r) JSON serialization -[![](static/benchmarks/techempower-json.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=json&l=zijocf-1r) +[![](static/benchmarks/techempower-json.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=json&l=zijocf-1r) Single query -[![](static/benchmarks/techempower-single-query.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=db&l=zijocf-1r) +[![](static/benchmarks/techempower-single-query.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=db&l=zijocf-1r) Multiple queries -[![](static/benchmarks/techempower-multiple-queries.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=query&l=zijocf-1r) +[![](static/benchmarks/techempower-multiple-queries.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=query&l=zijocf-1r) Data updates -[![](static/benchmarks/techempower-updates.png)](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=update&l=zijocf-1r) +[![](static/benchmarks/techempower-updates.png)](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=update&l=zijocf-1r) #### Go-Web [go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark) diff --git a/docs/context.md b/docs/context.md index cb092b2f..beb2c195 100644 --- a/docs/context.md +++ b/docs/context.md @@ -507,6 +507,21 @@ app.Get("/json", func(c *fiber.Ctx) { }) ``` +#### JsonBytes +This function accepts raw []byte bodies and sets the content header to application/json. This function is used if you do not need type assertion. +```go +// Function signature +c.Json(json []byte) + +// Example +app := fiber.New() +app.Get("/json", func(c *fiber.Ctx) { + c.JsonBytes([]byte(`"{"hello": "world"}"`)) +}) +app.Listen(8080) +``` + + #### Jsonp Sends a JSON response with JSONP support. This method is identical to [Json()](#json), except that it opts-in to JSONP callback support. @@ -515,6 +530,7 @@ By default, the JSONP callback name is simply callback. Override this by passing // Function signature c.Jsonp(v interface{}) error c.Jsonp(v interface{}, callback string) error + // Example type JsonStruct struct { name string @@ -536,6 +552,20 @@ app.Get("/", func(c *fiber.Ctx) { app.Listen(8080) ``` +#### JsonString +This function accepts raw string body and sets the content header to application/json. This function is used if you do not need type assertion. +```go +// Function signature +c.Json(json string) + +// Example +app := fiber.New() +app.Get("/json", func(c *fiber.Ctx) { + c.JsonString(`"{"hello": "world"}"`) +}) +app.Listen(8080) +``` + #### Links Joins the links followed by the propery to populate the response’s Link HTTP header field. ```go diff --git a/docs/index.html b/docs/index.html index 38d0a535..61f89e5e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,7 +19,7 @@