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