feat: support third party orm to interact with go-zero (#1286)

* fixes #987

* chore: fix test failure

* chore: add comments

* feat: support third party orm to interact with go-zero

* chore: refactor
This commit is contained in:
Kevin Wan
2021-12-01 20:22:15 +08:00
committed by GitHub
parent 543d590710
commit 9d528dddd6
24 changed files with 55 additions and 38 deletions

View File

@@ -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