mirror of https://github.com/gofiber/fiber.git
Add BodyParser
parent
545815ab95
commit
11f7d46306
|
@ -2,7 +2,7 @@ language: go
|
|||
|
||||
os:
|
||||
- linux
|
||||
- windows
|
||||
# - windows
|
||||
- osx
|
||||
go:
|
||||
- 1.13.x
|
||||
|
|
13
request.go
13
request.go
|
@ -9,11 +9,13 @@ package fiber
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
|
@ -194,6 +196,17 @@ func (ctx *Ctx) Body(args ...interface{}) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// BodyParser : https://gofiber.github.io/fiber/#/context?id=bodyparser
|
||||
func (ctx *Ctx) BodyParser(v interface{}) error {
|
||||
cType := getString(ctx.Fasthttp.Request.Header.ContentType())
|
||||
if cType == contentTypeJSON {
|
||||
return jsoniter.Unmarshal(ctx.Fasthttp.Request.Body(), v)
|
||||
} else if cType == contentTypeXML {
|
||||
return xml.Unmarshal(ctx.Fasthttp.Request.Body(), v)
|
||||
}
|
||||
return fmt.Errorf("Cannot Parse Content-Type: %v", cType)
|
||||
}
|
||||
|
||||
// Cookies : https://gofiber.github.io/fiber/#/context?id=cookies
|
||||
func (ctx *Ctx) Cookies(args ...interface{}) string {
|
||||
if len(args) == 0 {
|
||||
|
|
1
utils.go
1
utils.go
|
@ -64,7 +64,6 @@ func getRegex(path string) (*regexp.Regexp, error) {
|
|||
}
|
||||
|
||||
func getFiles(root string) (files []string, isDir bool, err error) {
|
||||
root = filepath.Clean(root)
|
||||
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
|
|
Loading…
Reference in New Issue