github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/example/redirect/rpc/sample.go (about)

     1  package rpc
     2  
     3  import (
     4  	"github.com/ronaksoft/rony"
     5  	"github.com/ronaksoft/rony/edge"
     6  	"github.com/ronaksoft/rony/errors"
     7  	"go.uber.org/zap"
     8  )
     9  
    10  /*
    11     Creation Time: 2021 - Jul - 04
    12     Created by:  (ehsan)
    13     Maintainers:
    14        1.  Ehsan N. Moosa (E2)
    15     Auditor: Ehsan N. Moosa (E2)
    16     Copyright Ronak Software Group 2020
    17  */
    18  
    19  //go:generate protoc -I=. -I=../../.. --go_out=paths=source_relative:. sample.proto
    20  //go:generate protoc -I=. -I=../../.. --gorony_out=paths=source_relative:. sample.proto
    21  func init() {}
    22  
    23  // Sample implements auto-generated service.ISample interface
    24  type Sample struct{}
    25  
    26  func (s *Sample) InfoWithClientRedirect(ctx *edge.RequestCtx, req *InfoRequest, res *InfoResponse) *rony.Error {
    27  	ctx.Log().Warn("Received", zap.Uint64("ReqRS", req.GetReplicaSet()), zap.Uint64("ServerRS", ctx.ReplicaSet()))
    28  	if req.GetReplicaSet() != ctx.ReplicaSet() {
    29  		ctx.PushRedirectRequest(req.GetReplicaSet())
    30  
    31  		return nil
    32  	}
    33  	res.ServerID = ctx.ServerID()
    34  	res.RandomText = req.GetRandomText()
    35  
    36  	return nil
    37  }
    38  
    39  func (s *Sample) InfoWithServerRedirect(ctx *edge.RequestCtx, req *InfoRequest, res *InfoResponse) *rony.Error {
    40  	ctx.Log().Warn("Received", zap.Uint64("ReplicaSet", req.GetReplicaSet()))
    41  	if req.GetReplicaSet() != ctx.ReplicaSet() {
    42  		err := TunnelRequestSampleInfoWithServerRedirect(ctx, req.GetReplicaSet(), req, res)
    43  		if err != nil {
    44  			ctx.Log().Warn("Got Error", zap.Error(err))
    45  
    46  			return errors.ErrInternalServer
    47  		}
    48  
    49  		return nil
    50  	}
    51  	res.ServerID = ctx.Cluster().ServerID()
    52  	res.RandomText = req.GetRandomText()
    53  
    54  	return nil
    55  }