Skip to content

Commit

Permalink
small refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannm committed Jan 15, 2024
1 parent bf77b4f commit d0229b1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions kit/bridge_north.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ type GatewayStartConfig struct {
ReusePort bool
}

// Gateway is main component of the EdgeServer. Without Gateway, the EdgeServer is not functional. You can use
// Gateway is the main component of the EdgeServer. Without Gateway, the EdgeServer is not functional. You can use
// some standard bundles in std/bundle path. However, if you need special handling of communication
// between your server and the clients you are free to implement your own Gateway.
// If you are a bundle developer need to work with interface otherwise you don't need to know
// between your server and clients, you are free to implement your own Gateway.
// If you are a bundle developer need to work with interface otherwise, you don't need to know
// much about this interface.
type Gateway interface {
// Start starts the gateway to accept connections.
Start(ctx context.Context, cfg GatewayStartConfig) error
// Shutdown shuts down the gateway gracefully.
Shutdown(ctx context.Context) error
// Register registers the route in the Bundle. This is how Bundle get information
// Register registers the route in the Bundle. This is how Bundle gets information
// about the services and their contracts.
Register(
serviceName, contractID string, enc Encoding, sel RouteSelector, input Message,
Expand All @@ -36,7 +36,7 @@ type Gateway interface {
Subscribe(d GatewayDelegate)
// Dispatch receives the messages from external clients and runs the execFunc with appropriate
// arguments. The user of the Gateway does not need to implement this. If you are using some
// standard bundles like std/gateway/fasthttp or std/gateway/fastws then all the implementation
// standard bundles like std/gateway/fasthttp or std/gateway/fastws, then all the implementation
// is taken care of.
Dispatch(ctx *Context, in []byte) (ExecuteArg, error)
}
Expand Down
3 changes: 3 additions & 0 deletions kit/bridge_south.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (sb *southBridge) genForwarderHandler(sel EdgeSelectorFunc) HandlerFunc {
)

ctx.Error(err)

// We should stop executing next handlers, since our request has been executed on
// a remote machine
ctx.StopExecution()
}
}
Expand Down
9 changes: 2 additions & 7 deletions kit/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (ctx *Context) executeRemote(arg executeRemoteArg) error {
you allow the processing flow to continue and pass control to the subsequent middleware functions
in the chain.
*/

func (ctx *Context) Next() {
ctx.handlerIndex++
for ctx.handlerIndex <= len(ctx.handlers) {
Expand Down Expand Up @@ -252,7 +253,7 @@ func (ctx *Context) OutTo(c Conn) *Envelope {
return newEnvelope(ctx, c, true)
}

// Error is useful for some kind of errors which you are not going to return it to the connection,
// Error is useful for some kind of errors that you are not going to return it to the connection,
// or you want to use its side effect for logging, monitoring, etc. This will call your ErrHandlerFunc.
// The boolean result indicates if 'err' was an actual error.
func (ctx *Context) Error(err error) bool {
Expand Down Expand Up @@ -297,12 +298,6 @@ func (ctx *Context) reset() {
ctx.ctx = nil
}

func (ctx *Context) isREST() bool {
_, ok := ctx.Conn().(RESTConn)

return ok
}

type ctxPool struct {
sync.Pool
ls *localStore
Expand Down
4 changes: 4 additions & 0 deletions kit/ctx_limited.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (ctx *LimitedContext) Conn() Conn {
return ctx.ctx.conn
}

func (ctx *LimitedContext) IsREST() bool {
return ctx.ctx.IsREST()
}

// SetHdr sets the common header key-value pairs, so in Out method we do not need to
// repeatedly set those. If you only want to set the header for an envelope, you can
// use Envelope.SetHdr method instead.
Expand Down
4 changes: 2 additions & 2 deletions kit/envelope_carrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type envelopeCarrier struct {
func (ec *envelopeCarrier) FillWithContext(ctx *Context) *envelopeCarrier {
ec.Data = &carrierData{
EnvelopeID: ctx.In().GetID(),
IsREST: ctx.isREST(),
IsREST: ctx.IsREST(),
MsgType: reflect.TypeOf(ctx.In().GetMsg()).String(),
Msg: marshalEnvelopeCarrier(ctx.In().GetMsg()),
ContractID: ctx.ContractID(),
Expand Down Expand Up @@ -65,7 +65,7 @@ func (ec *envelopeCarrier) FillWithContext(ctx *Context) *envelopeCarrier {
func (ec *envelopeCarrier) FillWithEnvelope(e *Envelope) *envelopeCarrier {
ec.Data = &carrierData{
EnvelopeID: utils.B2S(e.id),
IsREST: e.ctx.isREST(),
IsREST: e.ctx.IsREST(),
MsgType: reflect.TypeOf(e.GetMsg()).String(),
Msg: marshalEnvelopeCarrier(e.GetMsg()),
ContractID: e.ctx.ContractID(),
Expand Down

0 comments on commit d0229b1

Please sign in to comment.