Skip to content

Commit 7059c22

Browse files
authored
Merge pull request #454 from TarsCloud/perf/tars2go
perf(tars2go): reduce duplicate code generation, client add Endpoints method to get active endpoint.Endpoint
2 parents 8d679b9 + 079a222 commit 7059c22

File tree

5 files changed

+117
-99
lines changed

5 files changed

+117
-99
lines changed

examples/Tars2Go/go.mod

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module demo
22

33
go 1.14
4+
5+
require (
6+
github.com/TarsCloud/TarsGo v1.4.0
7+
github.com/golang/protobuf v1.5.3
8+
google.golang.org/protobuf v1.30.0
9+
)

tars/model/Servant.go tars/model/servant.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package model
33
import (
44
"context"
55

6+
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
7+
68
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
79
)
810

911
// Servant is interface for call the remote server.
1012
type Servant interface {
13+
Name() string
1114
TarsInvoke(ctx context.Context, cType byte,
1215
sFuncName string,
1316
buf []byte,
@@ -16,7 +19,7 @@ type Servant interface {
1619
resp *requestf.ResponsePacket) error
1720
TarsSetTimeout(t int)
1821
TarsSetProtocol(Protocol)
19-
Name() string
22+
Endpoints() []*endpoint.Endpoint
2023
SetPushCallback(callback func([]byte))
2124
}
2225

tars/servant.go

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ func (s *ServantProxy) TarsSetProtocol(proto model.Protocol) {
9090
s.proto = proto
9191
}
9292

93+
// Endpoints returns all active endpoint.Endpoint
94+
func (s *ServantProxy) Endpoints() []*endpoint.Endpoint {
95+
return s.manager.GetAllEndpoint()
96+
}
97+
9398
// 生成请求 ID
9499
func (s *ServantProxy) genRequestID() int32 {
95100
// 尽力防止溢出

0 commit comments

Comments
 (0)