Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
9530fa863f | |||
f3fb259eee | |||
67c15513a2 |
24
ctx.go
24
ctx.go
@ -110,12 +110,15 @@ func (c *Ctx) Cookies(key string, defaultValue ...string) string {
|
||||
func (c *Ctx) Next() error {
|
||||
c.index++
|
||||
|
||||
if c.index >= len(c.handlers) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
handler = c.handlers[c.index]
|
||||
)
|
||||
|
||||
//for c.index < len(c.handlers) {
|
||||
if handler != nil {
|
||||
if err = handler(c); err != nil {
|
||||
return err
|
||||
@ -123,7 +126,6 @@ func (c *Ctx) Next() error {
|
||||
}
|
||||
|
||||
c.index++
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -149,11 +151,24 @@ func (c *Ctx) Form(key string) string {
|
||||
return c.Request.FormValue(key)
|
||||
}
|
||||
|
||||
// FormValue fiber ctx function
|
||||
func (c *Ctx) FormValue(key string) string {
|
||||
return c.Request.FormValue(key)
|
||||
}
|
||||
|
||||
func (c *Ctx) FormFile(key string) (*multipart.FileHeader, error) {
|
||||
_, fh, err := c.Request.FormFile(key)
|
||||
return fh, err
|
||||
}
|
||||
|
||||
func (c *Ctx) MultipartForm() (*multipart.Form, error) {
|
||||
if err := c.Request.ParseMultipartForm(c.app.config.BodyLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.Request.MultipartForm, nil
|
||||
}
|
||||
|
||||
func (c *Ctx) Query(key string) string {
|
||||
return c.Request.URL.Query().Get(key)
|
||||
}
|
||||
@ -247,6 +262,11 @@ func (c *Ctx) SetHeader(key string, value string) {
|
||||
c.writermem.Header().Set(key, value)
|
||||
}
|
||||
|
||||
func (c *Ctx) SendStatus(code int) error {
|
||||
c.writermem.WriteHeader(code)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Ctx) SendString(data string) error {
|
||||
c.SetHeader("Content-Type", "text/plain")
|
||||
_, err := c.Write([]byte(data))
|
||||
|
@ -6,7 +6,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := nf.New(nf.Config{EnableNotImplementHandler: true})
|
||||
app := nf.New(nf.Config{})
|
||||
|
||||
app.Get("/ok", func(c *nf.Ctx) error {
|
||||
return c.SendStatus(200)
|
||||
})
|
||||
|
||||
api := app.Group("/api")
|
||||
api.Get("/1", func(c *nf.Ctx) error {
|
||||
|
33
xtest/multipart_form/main.go
Normal file
33
xtest/multipart_form/main.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := nf.New(nf.Config{BodyLimit: 10 * 1024 * 1024})
|
||||
|
||||
app.Post("/upload", func(c *nf.Ctx) error {
|
||||
fs, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
return resp.Resp400(c, err.Error())
|
||||
}
|
||||
|
||||
fm := make(map[string][]string)
|
||||
for key := range fs.File {
|
||||
if _, exist := fm[key]; !exist {
|
||||
fm[key] = make([]string, 0)
|
||||
}
|
||||
|
||||
for f := range fs.File[key] {
|
||||
fm[key] = append(fm[key], fs.File[key][f].Filename)
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Resp200(c, nf.Map{"value": fs.Value, "files": fm})
|
||||
})
|
||||
|
||||
log.Fatal(app.Run(":13322"))
|
||||
}
|
Reference in New Issue
Block a user