mirror of https://github.com/gofiber/fiber.git
Add JsonString & JsonBytes + Update benchmark links
parent
29091a54b4
commit
ec1ba416bf
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "1.2.2"
|
Version = "1.2.3"
|
||||||
// https://play.golang.org/p/r6GNeV1gbH
|
// https://play.golang.org/p/r6GNeV1gbH
|
||||||
banner = "" +
|
banner = "" +
|
||||||
" \x1b[1;32m _____ _ _\n" +
|
" \x1b[1;32m _____ _ _\n" +
|
||||||
|
|
|
@ -9,26 +9,26 @@
|
||||||
|
|
||||||
|
|
||||||
Below you can see the results of tested go frameworks responding in plaintext.
|
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 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=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext).
|
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
|
Plaintext
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext&l=zijocf-1r)
|
||||||
|
|
||||||
Plaintext latency
|
Plaintext latency
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=plaintext&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=plaintext&l=zijocf-1r)
|
||||||
|
|
||||||
JSON serialization
|
JSON serialization
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=json&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=json&l=zijocf-1r)
|
||||||
|
|
||||||
Single query
|
Single query
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=db&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=db&l=zijocf-1r)
|
||||||
|
|
||||||
Multiple queries
|
Multiple queries
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=query&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=query&l=zijocf-1r)
|
||||||
|
|
||||||
Data updates
|
Data updates
|
||||||
[](https://www.techempower.com/benchmarks/#section=test&runid=8721f3a4-7b13-4703-9cd8-91b6779668c2&hw=ph&test=update&l=zijocf-1r)
|
[](https://www.techempower.com/benchmarks/#section=test&runid=350f0783-cc9b-4259-9831-28987799782a&hw=ph&test=update&l=zijocf-1r)
|
||||||
|
|
||||||
#### Go-Web
|
#### Go-Web
|
||||||
[go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark)
|
[go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark)
|
||||||
|
|
|
@ -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
|
#### Jsonp
|
||||||
Sends a JSON response with JSONP support. This method is identical to [Json()](#json), except that it opts-in to JSONP callback support.
|
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
|
// Function signature
|
||||||
c.Jsonp(v interface{}) error
|
c.Jsonp(v interface{}) error
|
||||||
c.Jsonp(v interface{}, callback string) error
|
c.Jsonp(v interface{}, callback string) error
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
type JsonStruct struct {
|
type JsonStruct struct {
|
||||||
name string
|
name string
|
||||||
|
@ -536,6 +552,20 @@ app.Get("/", func(c *fiber.Ctx) {
|
||||||
app.Listen(8080)
|
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
|
#### Links
|
||||||
Joins the links followed by the propery to populate the response’s Link HTTP header field.
|
Joins the links followed by the propery to populate the response’s Link HTTP header field.
|
||||||
```go
|
```go
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
name: 'Fiber v1.2.2',
|
name: 'Fiber v1.2.3',
|
||||||
repo: 'gofiber/fiber',
|
repo: 'gofiber/fiber',
|
||||||
loadSidebar: "sidebar.md",
|
loadSidebar: "sidebar.md",
|
||||||
homepage: 'getting_started.md',
|
homepage: 'getting_started.md',
|
||||||
|
|
12
response.go
12
response.go
|
@ -154,6 +154,12 @@ func (ctx *Ctx) Json(v interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JsonBytes : https://gofiber.github.io/fiber/#/context?id=jsonbytes
|
||||||
|
func (ctx *Ctx) JsonBytes(raw []byte) {
|
||||||
|
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJson)
|
||||||
|
ctx.Fasthttp.Response.SetBodyString(getString(raw))
|
||||||
|
}
|
||||||
|
|
||||||
// Jsonp : https://gofiber.github.io/fiber/#/context?id=jsonp
|
// Jsonp : https://gofiber.github.io/fiber/#/context?id=jsonp
|
||||||
func (ctx *Ctx) Jsonp(v interface{}, cb ...string) error {
|
func (ctx *Ctx) Jsonp(v interface{}, cb ...string) error {
|
||||||
raw, err := jsoniter.Marshal(&v)
|
raw, err := jsoniter.Marshal(&v)
|
||||||
|
@ -172,6 +178,12 @@ func (ctx *Ctx) Jsonp(v interface{}, cb ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JsonString : https://gofiber.github.io/fiber/#/context?id=jsonstring
|
||||||
|
func (ctx *Ctx) JsonString(raw string) {
|
||||||
|
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJson)
|
||||||
|
ctx.Fasthttp.Response.SetBodyString(raw)
|
||||||
|
}
|
||||||
|
|
||||||
// Links : https://gofiber.github.io/fiber/#/context?id=links
|
// Links : https://gofiber.github.io/fiber/#/context?id=links
|
||||||
func (ctx *Ctx) Links(link ...string) {
|
func (ctx *Ctx) Links(link ...string) {
|
||||||
h := ""
|
h := ""
|
||||||
|
|
Loading…
Reference in New Issue