Giter Site home page Giter Site logo

droplet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

droplet's Issues

missing method GetHeader

go/pkg/mod/github.com/shiningrush/droplet/wrapper/[email protected]/gin.go:13:20: cannot use ctx.Writer (variable of type "github.com/gin-gonic/gin".ResponseWriter) as data.ResponseWriter value in struct literal: "github.com/gin-gonic/gin".ResponseWriter does not implement data.ResponseWriter (missing method GetHeader)

Feat: need a way to get request body

Hello. Now there is no way to get the request body in gin's hander. because you read the body to inject field.
I think it's needed to save the request body for other use.

IMO there are two ways to do this:

  1. Set the dict with the request body when reading the body.
  2. Use a buffer to save the request body and implate the http.Requests GetBody function.

对代码写法的疑问

ret, _ := droplet.NewPipe().
	Add(middleware.NewHttpInfoInjectorMiddleware(middleware.HttpInfoInjectorOption{
		ReqFunc: func() *http.Request {
			return ctx.Request
		},
	})).
	Add(middleware.NewRespReshapeMiddleware()).
	Add(middleware.NewHttpInputMiddleWare(middleware.HttpInputOption{
		PathParamsFunc: func(key string) string {
			return ctx.Param(key)
		},
		InputType:      opt.InputType,
		IsReadFromBody: opt.IsReadFromBody,
	})).
	Add(middleware.NewTrafficLogMiddleware(opt.TrafficLogOpt)).
	SetOrchestrator(opt.Orchestrator).
	Run(handler, droplet.InitContext(dCtx))

这里为什么要用"生成器模式"呢?而不是下面这样呢?

ret, _ := droplet.NewPipe()
ret.Add(middleware.NewHttpInfoInjectorMiddleware(middleware.HttpInfoInjectorOption{
  ReqFunc: func() *http.Request {
	  return ctx.Request
  },
  }))
...

How to access Keys of gin.Context?

Hi, I set the user infomation in a filter of gin, the filter is as follows:

func Authentication() gin.HandlerFunc {
    return func(c *gin.Context){
        userId := "123"
        c.Set("userId", userId)
        c.Next()
    }
}

How should I get the value of userId?

func (h *Handler) current(c droplet.Context) (interface{}, error){
    userId := ????
}

Feat: droplet.Context can save the gin.Context

In some situations, we need to use gin.Context to save the key and value in the middleware.But now, I can't find a way to get the gin.Context though droplect.Context.

See :

dCtx.SetContext(ctx.Request.Context())

So I recommend adding a field to save the gin.Context.Then we can get the gin.Context in our interface handler.

Why not use *gin.Context in gin wrapper ??

I see the wraps code use request.Context() like this dCtx.SetContext(input.Req.Context()) how do id use the gin context values set by gin middlewares ?? this is really not a design problem, right?

bug: get request occurs error in binding query param

version:
github.com/shiningrush/droplet v0.3.0
github.com/shiningrush/droplet/wrapper/gin v0.2.1

phenomenon
when a requst use get method carry query param. it's param binding occurs error. different param order appears different phenomenon.
the following is my test:

  1. this is my struct
    `

    type GetTestInput struct {
     PageSize   int `json:"pageSize" form:"pageSize" auto_read:"pageSize"`
     PageNumber int `json:"pageNum" form:"pageNum" auto_read:"pageNum"`
     ClusterId  int    `auto_read:"ClusterId,header" json:"ClusterId"`
     InnerAddr  string `auto_read:"innerAddr,query" json:"innerAddr"`
     OutterAddr string `auto_read:"outterAddr,query" json:"outterAddr"`
     Path       string `auto_read:"path,query" json:"path"`
     Status     *int   `auto_read:"status,query" json:"status"`
     Labels     string `auto_read:"labels,query" json:"labels"`
     HomeUnit   *int   `auto_read:"homeUnit,query" json:"homeUnit"`
     }
    

`
when I use the above struct and send the following request:
(the ClusterId is in header)
http://127.0.0.1:8080/api/v1/test?labels=aaa&pageNum=1&pageSize=50&homeUnit=1
image

when I use the following struct(it just change the property order ):
`

   type GetTestInput struct {
        Labels     string `auto_read:"labels,query" json:"labels"`
    PageSize   int `json:"pageSize" form:"pageSize" auto_read:"pageSize"`
    PageNumber int `json:"pageNum" form:"pageNum" auto_read:"pageNum"`
    ClusterId  int    `auto_read:"ClusterId,header" json:"ClusterId"`
    InnerAddr  string `auto_read:"innerAddr,query" json:"innerAddr"`
    OutterAddr string `auto_read:"outterAddr,query" json:"outterAddr"`
    Path       string `auto_read:"path,query" json:"path"`
    Status     *int   `auto_read:"status,query" json:"status"`
    HomeUnit   *int   `auto_read:"homeUnit,query" json:"homeUnit"`
    }

`
then I use the above struct and send the following request:
http://127.0.0.1:8080/api/v1/test?labels=aaa&pageNum=1&pageSize=50&homeUnit=1
it appears as below:
image

please pay attention to "labels", just change the order in the same struct. one could get it's value. the other don't

I want to know why this occurs.

panic when upload file

struct:

type ImportInput struct {
	Force byte `auto_read:"force,query"`
	FileName string `auto_read:"_file"`
	FileContent []byte `auto_read:"file"`
}

error log:

reflect: call of reflect.Value.Set on zero Value
[Recovery] 2021/01/27 - 08:47:31 panic recovered:

reflect: call of reflect.Value.Set on zero Value
/usr/local/Cellar/go/1.15.2/libexec/src/reflect/value.go:234 (0x10a0c2f)
	flag.mustBeExportedSlow: panic(&ValueError{methodNameSkip(), Invalid})
/usr/local/Cellar/go/1.15.2/libexec/src/reflect/value.go:228 (0x10a6cd5)
	flag.mustBeExported: f.mustBeExportedSlow()
/usr/local/Cellar/go/1.15.2/libexec/src/reflect/value.go:1549 (0x10a6cbb)
	Value.Set: x.mustBeExported() // do not let unexported x leak
/Users/test/data/www/droplet/middleware/http_input.go:161 (0x1635a5c)
	(*HttpInputMiddleware).injectFieldFromUrlAndMap: input.Field(i).Set(reflect.ValueOf(tarVal))
/Users/test/data/www/droplet/middleware/http_input.go:63 (0x1634789)
	(*HttpInputMiddleware).Handle: if err := mw.injectFieldFromUrlAndMap(pInput); err != nil {
/Users/test/data/www/droplet/middleware/base.go:16 (0x16368e1)
	(*BaseMiddleware).Handle: return mw.next.Handle(ctx)
/Users/test/data/www/droplet/middleware/http_resp_reshap.go:19 (0x16368af)
	(*HttpRespReshapeMiddleware).Handle: if err := mw.BaseMiddleware.Handle(ctx); err != nil {
/Users/test/data/www/droplet/middleware/base.go:16 (0x19268f0)
	(*BaseMiddleware).Handle: return mw.next.Handle(ctx)
/Users/test/data/www/apisix-dashboard/api/internal/filter/authentication.go:90 (0x19268be)
	(*AuthenticationMiddleware).Handle: return mw.BaseMiddleware.Handle(ctx)
/Users/test/data/www/droplet/middleware/base.go:16 (0x18e0dea)
	(*BaseMiddleware).Handle: return mw.next.Handle(ctx)
/Users/test/data/www/apisix-dashboard/api/internal/handler/handler.go:78 (0x18e0dc1)
	(*ErrorTransformMiddleware).Handle: if err := mw.BaseMiddleware.Handle(ctx); err != nil {
/Users/test/data/www/droplet/middleware/base.go:16 (0x163446b)
	(*BaseMiddleware).Handle: return mw.next.Handle(ctx)
/Users/test/data/www/droplet/middleware/http_injector.go:28 (0x1634476)
	(*HttpInfoInjectorMiddleware).Handle: return mw.BaseMiddleware.Handle(ctx)
/Users/test/data/www/droplet/pipe.go:84 (0x138c602)
	(*BasePipe).Run: err := p.mws[0].Handle(initCtx)
/Users/test/go/pkg/mod/github.com/shiningrush/droplet/wrapper/[email protected]/gin.go:41 (0x16385c4)
	Wraps.func1: Run(handler, droplet.InitContext(dCtx))
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/data/www/apisix-dashboard/api/internal/filter/recover.go:53 (0x192a5cd)
	RecoverHandler.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/data/www/apisix-dashboard/api/internal/filter/schema.go:193 (0x192b3e7)
	SchemaCheck.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/data/www/apisix-dashboard/api/internal/filter/logging.go:35 (0x19294de)
	RequestLogHandler.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/data/www/apisix-dashboard/api/internal/filter/request_id.go:41 (0x192a8a6)
	RequestId.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/data/www/apisix-dashboard/api/internal/filter/cors.go:31 (0x1929286)
	CORS.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/go/pkg/mod/github.com/gin-contrib/[email protected]/sessions.go:52 (0x191c8c5)
	Sessions.func1: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1620f1a)
	(*Context).Next: c.handlers[c.index](c)
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:409 (0x162af39)
	(*Engine).handleHTTPRequest: c.Next()
/Users/test/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0x162a62c)
	(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/Cellar/go/1.15.2/libexec/src/net/http/server.go:2843 (0x130c342)
	serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/Cellar/go/1.15.2/libexec/src/net/http/server.go:1925 (0x1307a4c)
	(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/Cellar/go/1.15.2/libexec/src/runtime/asm_amd64.s:1374 (0x1071540)
	goexit: BYTE	$0x90	// NOP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.