diff --git a/core/discov/config.go b/core/discov/config.go index 66c088b6..f6361e81 100644 --- a/core/discov/config.go +++ b/core/discov/config.go @@ -13,7 +13,7 @@ var ( type EtcdConf struct { Hosts []string Key string - ServerID int64 `json:",optional"` + ID int64 `json:",optional"` User string `json:",optional"` Pass string `json:",optional"` CertFile string `json:",optional"` @@ -27,9 +27,9 @@ func (c EtcdConf) HasAccount() bool { return len(c.User) > 0 && len(c.Pass) > 0 } -// HasServerID returns if ServerID provided. -func (c EtcdConf) HasServerID() bool { - return c.ServerID > 0 +// HasID returns if ID provided. +func (c EtcdConf) HasID() bool { + return c.ID > 0 } // HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided. diff --git a/core/discov/config_test.go b/core/discov/config_test.go index 732f7b55..aa9f8bb3 100644 --- a/core/discov/config_test.go +++ b/core/discov/config_test.go @@ -81,35 +81,89 @@ func TestEtcdConf_HasAccount(t *testing.T) { } } -func TestEtcdConf_HasServerID(t *testing.T) { +func TestEtcdConf_HasID(t *testing.T) { tests := []struct { EtcdConf hasServerID bool }{ { EtcdConf: EtcdConf{ - Hosts: []string{"any"}, - ServerID: -1, + Hosts: []string{"any"}, + ID: -1, }, hasServerID: false, }, { EtcdConf: EtcdConf{ - Hosts: []string{"any"}, - ServerID: 0, + Hosts: []string{"any"}, + ID: 0, }, hasServerID: false, }, { EtcdConf: EtcdConf{ - Hosts: []string{"any"}, - ServerID: 10000, + Hosts: []string{"any"}, + ID: 10000, }, hasServerID: true, }, } for _, test := range tests { - assert.Equal(t, test.hasServerID, test.EtcdConf.HasServerID()) + assert.Equal(t, test.hasServerID, test.EtcdConf.HasID()) + } +} + +func TestEtcdConf_HasTLS(t *testing.T) { + tests := []struct { + name string + conf EtcdConf + want bool + }{ + { + name: "empty config", + conf: EtcdConf{}, + want: false, + }, + { + name: "missing CertFile", + conf: EtcdConf{ + CertKeyFile: "key", + CACertFile: "ca", + }, + want: false, + }, + { + name: "missing CertKeyFile", + conf: EtcdConf{ + CertFile: "cert", + CACertFile: "ca", + }, + want: false, + }, + { + name: "missing CACertFile", + conf: EtcdConf{ + CertFile: "cert", + CertKeyFile: "key", + }, + want: false, + }, + { + name: "valid config", + conf: EtcdConf{ + CertFile: "cert", + CertKeyFile: "key", + CACertFile: "ca", + }, + want: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.conf.HasTLS() + assert.Equal(t, tt.want, got) + }) } } diff --git a/tools/goctl/model/sql/gen/keys_test.go b/tools/goctl/model/sql/gen/keys_test.go index c54cc4fe..145f136e 100644 --- a/tools/goctl/model/sql/gen/keys_test.go +++ b/tools/goctl/model/sql/gen/keys_test.go @@ -76,9 +76,9 @@ func TestGenCacheKeys(t *testing.T) { VarExpression: `cacheGoZeroUserIdPrefix = "cache:goZero:user:id:"`, KeyLeft: "goZeroUserIdKey", KeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, id)`, - DataKeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.Id)`, + DataKeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.ID)`, KeyExpression: `goZeroUserIdKey := fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, id)`, - DataKeyExpression: `goZeroUserIdKey := fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.Id)`, + DataKeyExpression: `goZeroUserIdKey := fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.ID)`, FieldNameJoin: []string{"id"}, }) }()) @@ -170,9 +170,9 @@ func TestGenCacheKeys(t *testing.T) { VarExpression: `cacheUserIdPrefix = "cache:user:id:"`, KeyLeft: "userIdKey", KeyRight: `fmt.Sprintf("%s%v", cacheUserIdPrefix, id)`, - DataKeyRight: `fmt.Sprintf("%s%v", cacheUserIdPrefix, data.Id)`, + DataKeyRight: `fmt.Sprintf("%s%v", cacheUserIdPrefix, data.ID)`, KeyExpression: `userIdKey := fmt.Sprintf("%s%v", cacheUserIdPrefix, id)`, - DataKeyExpression: `userIdKey := fmt.Sprintf("%s%v", cacheUserIdPrefix, data.Id)`, + DataKeyExpression: `userIdKey := fmt.Sprintf("%s%v", cacheUserIdPrefix, data.ID)`, FieldNameJoin: []string{"id"}, }) }()) diff --git a/zrpc/internal/clientinterceptors/tracinginterceptor.go b/zrpc/internal/clientinterceptors/tracinginterceptor.go index adf814b3..006c4691 100644 --- a/zrpc/internal/clientinterceptors/tracinginterceptor.go +++ b/zrpc/internal/clientinterceptors/tracinginterceptor.go @@ -2,7 +2,6 @@ package clientinterceptors import ( "context" - "github.com/zeromicro/go-zero/core/lang" "io" ztrace "github.com/zeromicro/go-zero/core/trace" @@ -95,7 +94,7 @@ type ( Finished chan error desc *grpc.StreamDesc events chan streamEvent - eventsDone chan lang.PlaceholderType + eventsDone chan struct{} receivedMessageID int sentMessageID int } diff --git a/zrpc/internal/rpcpubserver.go b/zrpc/internal/rpcpubserver.go index 58f6a9b3..3efde008 100644 --- a/zrpc/internal/rpcpubserver.go +++ b/zrpc/internal/rpcpubserver.go @@ -26,8 +26,8 @@ func NewRpcPubServer(etcd discov.EtcdConf, listenOn string, middlewares ServerMi pubOpts = append(pubOpts, discov.WithPubEtcdTLS(etcd.CertFile, etcd.CertKeyFile, etcd.CACertFile, etcd.InsecureSkipVerify)) } - if etcd.HasServerID() { - pubOpts = append(pubOpts, discov.WithId(etcd.ServerID)) + if etcd.HasID() { + pubOpts = append(pubOpts, discov.WithId(etcd.ID)) } pubClient := discov.NewPublisher(etcd.Hosts, etcd.Key, pubListenOn, pubOpts...) return pubClient.KeepAlive() diff --git a/zrpc/internal/rpcpubserver_test.go b/zrpc/internal/rpcpubserver_test.go index e7e99dc5..9c9f397b 100644 --- a/zrpc/internal/rpcpubserver_test.go +++ b/zrpc/internal/rpcpubserver_test.go @@ -12,6 +12,7 @@ func TestNewRpcPubServer(t *testing.T) { s, err := NewRpcPubServer(discov.EtcdConf{ User: "user", Pass: "pass", + ID: 10, }, "", ServerMiddlewaresConf{}) assert.NoError(t, err) assert.NotPanics(t, func() {