mirror of https://github.com/gofiber/fiber.git
Faster JSON serializing
parent
435d4b78ef
commit
39f08beb80
14
context.go
14
context.go
|
@ -1,17 +1,18 @@
|
|||
package fiber
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pquerna/ffjson/ffjson"
|
||||
"github.com/json-iterator/go"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
// Next :
|
||||
func (ctx *Ctx) Next() {
|
||||
ctx.next = true
|
||||
|
@ -217,11 +218,12 @@ func (ctx *Ctx) Get(key string) string {
|
|||
|
||||
// Json :
|
||||
func (ctx *Ctx) Json(v interface{}) error {
|
||||
raw, err := json.Marshal(&v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Set("Content-Type", "application/json")
|
||||
b := bytes.NewBuffer(nil)
|
||||
enc := ffjson.NewEncoder(b)
|
||||
err := enc.Encode(v)
|
||||
ctx.Send(b.Bytes())
|
||||
ctx.Send(b2s(raw))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,12 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
// ParseJSON "github.com/tidwall/gjson"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
const (
|
||||
Version = `v0.3.0`
|
||||
Version = `v0.3.1`
|
||||
banner = ` _____ _ _
|
||||
| __|_| |_ ___ ___
|
||||
| __| | . | -_| _|
|
||||
|
@ -66,7 +67,6 @@ type Settings struct {
|
|||
// Fiber :
|
||||
type Fiber struct {
|
||||
routes []*route
|
||||
methods []string
|
||||
Settings *Settings
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ func (r *Fiber) Listen(args ...interface{}) {
|
|||
r.Settings.NoDefaultServerHeader = false
|
||||
}
|
||||
server := &fasthttp.Server{
|
||||
// Express custom handler
|
||||
// Fiber custom handler
|
||||
Handler: r.handler,
|
||||
// Server settings
|
||||
Name: r.Settings.Name,
|
||||
|
@ -355,7 +355,6 @@ func (r *Fiber) Listen(args ...interface{}) {
|
|||
if !r.Settings.HideBanner {
|
||||
fmt.Printf(color.HiCyanString(banner), color.GreenString(":"+port), color.HiBlackString("("+Version+")"))
|
||||
}
|
||||
// fmt.Printf(banner, Version)
|
||||
if r.Settings.TLSEnable {
|
||||
if err := server.ListenAndServeTLS(fmt.Sprintf("%s:%s", addr, port), r.Settings.CertFile, r.Settings.CertKey); err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in New Issue