add init direct

pull/109/head
longXboy 6 years ago
parent 40f5515e85
commit 3c919192d7
  1. 6
      pkg/net/rpc/warden/client.go
  2. 3
      pkg/net/rpc/warden/server.go

@ -18,8 +18,6 @@ import (
"github.com/bilibili/kratos/pkg/net/netutil/breaker"
"github.com/bilibili/kratos/pkg/net/rpc/warden/balancer/p2c"
"github.com/bilibili/kratos/pkg/net/rpc/warden/internal/status"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver/direct"
"github.com/bilibili/kratos/pkg/net/trace"
xtime "github.com/bilibili/kratos/pkg/time"
@ -156,8 +154,6 @@ func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error) {
// NewClient returns a new blank Client instance with a default client interceptor.
// opt can be used to add grpc dial options.
func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client {
// Do not initialize in the registration, otherwise it may cause the resvoler in the business code to not register.
resolver.Register(direct.New())
c := new(Client)
if err := c.SetConfig(conf); err != nil {
panic(err)
@ -171,8 +167,6 @@ func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client {
// DefaultClient returns a new default Client instance with a default client interceptor and default dialoption.
// opt can be used to add grpc dial options.
func DefaultClient() *Client {
// Do not initialize in the registration, otherwise it may cause the resvoler in the business code to not register.
resolver.Register(direct.New())
_once.Do(func() {
_defaultClient = NewClient(nil)
})

@ -19,6 +19,8 @@ import (
//this package is for json format response
_ "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/encoding/json"
"github.com/bilibili/kratos/pkg/net/rpc/warden/internal/status"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver/direct"
"github.com/pkg/errors"
"google.golang.org/grpc"
@ -135,6 +137,7 @@ func (s *Server) handle() grpc.UnaryServerInterceptor {
func init() {
addFlag(flag.CommandLine)
resolver.Register(direct.New())
}
func addFlag(fs *flag.FlagSet) {

Loading…
Cancel
Save