|
@@ -4,6 +4,7 @@ import (
|
|
|
"github.com/tal-tech/go-zero/core/discov"
|
|
|
"github.com/tal-tech/go-zero/core/service"
|
|
|
"github.com/tal-tech/go-zero/core/stores/redis"
|
|
|
+ "github.com/tal-tech/go-zero/zrpc/resolver"
|
|
|
)
|
|
|
|
|
|
type (
|
|
@@ -67,6 +68,25 @@ func (sc RpcServerConf) Validate() error {
|
|
|
return sc.Redis.Validate()
|
|
|
}
|
|
|
|
|
|
+// BuildTarget builds the rpc target from the given config.
|
|
|
+func (cc RpcClientConf) BuildTarget() (string, error) {
|
|
|
+ if len(cc.Endpoints) > 0 {
|
|
|
+ return resolver.BuildDirectTarget(cc.Endpoints), nil
|
|
|
+ } else if len(cc.Target) > 0 {
|
|
|
+ return cc.Target, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := cc.Etcd.Validate(); err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ if cc.Etcd.HasAccount() {
|
|
|
+ discov.RegisterAccount(cc.Etcd.Hosts, cc.Etcd.User, cc.Etcd.Pass)
|
|
|
+ }
|
|
|
+
|
|
|
+ return resolver.BuildDiscovTarget(cc.Etcd.Hosts, cc.Etcd.Key), nil
|
|
|
+}
|
|
|
+
|
|
|
// HasCredential checks if there is a credential in config.
|
|
|
func (cc RpcClientConf) HasCredential() bool {
|
|
|
return len(cc.App) > 0 && len(cc.Token) > 0
|