diff --git a/.travis.yml b/.travis.yml index c087959d..1e4f6a69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: go os: - linux - - windows +# - windows - osx go: - 1.13.x diff --git a/request.go b/request.go index efbde50c..23a0aa9f 100644 --- a/request.go +++ b/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 { diff --git a/utils.go b/utils.go index e7c817bd..3ac0f0e0 100644 --- a/utils.go +++ b/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)