Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehsan N. Moosa committed Apr 22, 2021
1 parent faff65d commit 20cc720
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rest/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
*/

type Factory struct {
onRequest func(ctx *Context)
onRequest func(ctx *Context) error
onResponse func(envelope *rony.MessageEnvelope) (*pools.ByteBuffer, map[string]string)
}

func NewFactory(
onRequest func(ctx *Context),
onRequest func(ctx *Context) error,
onResponse func(envelope *rony.MessageEnvelope) (*pools.ByteBuffer, map[string]string),
) *Factory {
return &Factory{
Expand Down
9 changes: 7 additions & 2 deletions rest/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/ronaksoft/rony"
"github.com/ronaksoft/rony/internal/gateway"
"github.com/ronaksoft/rony/pools"
"github.com/ronaksoft/rony/tools"
"google.golang.org/protobuf/proto"
)

Expand All @@ -18,7 +19,7 @@ import (

type Handle struct {
ctx *Context
onRequest func(ctx *Context)
onRequest func(ctx *Context) error
onResponse func(envelope *rony.MessageEnvelope) (*pools.ByteBuffer, map[string]string)
inputBuf *pools.ByteBuffer
}
Expand All @@ -30,7 +31,11 @@ func (h *Handle) OnRequest(conn rony.Conn, ctx *gateway.RequestCtx) []byte {
}

h.ctx.me = rony.PoolMessageEnvelope.Get()
h.onRequest(h.ctx)
err := h.onRequest(h.ctx)
if err != nil {
_ = conn.SendBinary(0, tools.StrToByte(err.Error()))
return nil
}
mo := proto.MarshalOptions{UseCachedSize: true}
h.inputBuf = pools.Buffer.GetCap(mo.Size(h.ctx.me))
rony.PoolMessageEnvelope.Put(h.ctx.me)
Expand Down

0 comments on commit 20cc720

Please sign in to comment.