+1
This commit is contained in:
parent
f44813431d
commit
d0f10cec62
@ -118,3 +118,4 @@ func (d *RegisterHandler) register(
|
|||||||
Ok: true,
|
Ok: true,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +48,11 @@ type Request struct {
|
|||||||
ID string
|
ID string
|
||||||
Session *models.Session
|
Session *models.Session
|
||||||
User *models.User
|
User *models.User
|
||||||
|
// ResolveValues - data required to process request.
|
||||||
ResolveValues *sync.Map
|
ResolveValues *sync.Map
|
||||||
|
// Metadata - an additional data, usually added with preprocessing.
|
||||||
Metadata *sync.Map
|
Metadata *sync.Map
|
||||||
|
// Request body
|
||||||
Body []byte
|
Body []byte
|
||||||
RawReq *http.Request
|
RawReq *http.Request
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,14 @@ type Handler interface {
|
|||||||
GetName() string
|
GetName() string
|
||||||
GetRequiredResolveParams() []string
|
GetRequiredResolveParams() []string
|
||||||
GetProcessFn() func(ctx context.Context, req *common.Request, w Writer) error
|
GetProcessFn() func(ctx context.Context, req *common.Request, w Writer) error
|
||||||
|
GetPreprocessFn() func(ctx context.Context, req *common.Request, w Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseHandler struct {
|
type BaseHandler struct {
|
||||||
Name string
|
Name string
|
||||||
RequiredResolveParams []string
|
RequiredResolveParams []string
|
||||||
ProcessFn func(ctx context.Context, req *common.Request, w Writer) error
|
ProcessFn func(ctx context.Context, req *common.Request, w Writer) error
|
||||||
|
PreprocessFn func(ctx context.Context, req *common.Request, w Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *BaseHandler {
|
func New() *BaseHandler {
|
||||||
@ -42,6 +44,11 @@ func (h *BaseHandler) WithProcessFunc(fn func(ctx context.Context, req *common.R
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) WithPreprocessFunc(fn func(ctx context.Context, req *common.Request, w Writer) error) *BaseHandler {
|
||||||
|
h.PreprocessFn = fn
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
func (h *BaseHandler) GetName() string {
|
func (h *BaseHandler) GetName() string {
|
||||||
return h.Name
|
return h.Name
|
||||||
}
|
}
|
||||||
@ -53,3 +60,7 @@ func (h *BaseHandler) GetRequiredResolveParams() []string {
|
|||||||
func (h *BaseHandler) GetProcessFn() func(ctx context.Context, req *common.Request, w Writer) error {
|
func (h *BaseHandler) GetProcessFn() func(ctx context.Context, req *common.Request, w Writer) error {
|
||||||
return h.ProcessFn
|
return h.ProcessFn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) GetPreprocessFn() func(ctx context.Context, req *common.Request, w Writer) error {
|
||||||
|
return h.PreprocessFn
|
||||||
|
}
|
||||||
|
@ -47,8 +47,12 @@ func (p *GinProcessor) Process(handler handler.Handler) gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Call preprocessinf fn's, middlewares etc.
|
// 3. Call preprocessing fn's, middlewares etc.
|
||||||
// ....
|
if err = handler.GetPreprocessFn()(ctx, req, wrapGin(ctx)); err != nil {
|
||||||
|
p.writeError(ctx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 4. Call handler.ProcessFn
|
// 4. Call handler.ProcessFn
|
||||||
if err = handler.GetProcessFn()(ctx, req, wrapGin(ctx)); err != nil {
|
if err = handler.GetProcessFn()(ctx, req, wrapGin(ctx)); err != nil {
|
||||||
p.writeError(ctx, err)
|
p.writeError(ctx, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user