Skip to content

Commit

Permalink
Merge pull request #454 from TarsCloud/perf/tars2go
Browse files Browse the repository at this point in the history
perf(tars2go): reduce duplicate code generation, client add Endpoints method to get active endpoint.Endpoint
  • Loading branch information
lbbniu authored Apr 26, 2023
2 parents 8d679b9 + 079a222 commit 7059c22
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 99 deletions.
6 changes: 6 additions & 0 deletions examples/Tars2Go/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module demo

go 1.14

require (
github.com/TarsCloud/TarsGo v1.4.0
github.com/golang/protobuf v1.5.3
google.golang.org/protobuf v1.30.0
)
5 changes: 4 additions & 1 deletion tars/model/Servant.go → tars/model/servant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package model
import (
"context"

"github.com/TarsCloud/TarsGo/tars/util/endpoint"

"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
)

// Servant is interface for call the remote server.
type Servant interface {
Name() string
TarsInvoke(ctx context.Context, cType byte,
sFuncName string,
buf []byte,
Expand All @@ -16,7 +19,7 @@ type Servant interface {
resp *requestf.ResponsePacket) error
TarsSetTimeout(t int)
TarsSetProtocol(Protocol)
Name() string
Endpoints() []*endpoint.Endpoint
SetPushCallback(callback func([]byte))
}

Expand Down
5 changes: 5 additions & 0 deletions tars/servant.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (s *ServantProxy) TarsSetProtocol(proto model.Protocol) {
s.proto = proto
}

// Endpoints returns all active endpoint.Endpoint
func (s *ServantProxy) Endpoints() []*endpoint.Endpoint {
return s.manager.GetAllEndpoint()
}

// 生成请求 ID
func (s *ServantProxy) genRequestID() int32 {
// 尽力防止溢出
Expand Down
Loading

0 comments on commit 7059c22

Please sign in to comment.