@ -8,6 +8,7 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/registry"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver"
)
)
@ -37,20 +38,29 @@ func WithInsecure(insecure bool) Option {
}
}
}
}
// DisableDebugLog disables update instances log.
func DisableDebugLog ( ) Option {
return func ( b * builder ) {
b . debugLogDisabled = true
}
}
type builder struct {
type builder struct {
discoverer registry . Discovery
discoverer registry . Discovery
logger log . Logger
logger log . Logger
timeout time . Duration
timeout time . Duration
insecure bool
insecure bool
debugLogDisabled bool
}
}
// NewBuilder creates a builder which is used to factory registry resolvers.
// NewBuilder creates a builder which is used to factory registry resolvers.
func NewBuilder ( d registry . Discovery , opts ... Option ) resolver . Builder {
func NewBuilder ( d registry . Discovery , opts ... Option ) resolver . Builder {
b := & builder {
b := & builder {
discoverer : d ,
discoverer : d ,
logger : log . GetLogger ( ) ,
logger : log . GetLogger ( ) ,
timeout : time . Second * 10 ,
timeout : time . Second * 10 ,
insecure : false ,
insecure : false ,
debugLogDisabled : false ,
}
}
for _ , o := range opts {
for _ , o := range opts {
o ( b )
o ( b )
@ -79,12 +89,13 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, opts res
return nil , err
return nil , err
}
}
r := & discoveryResolver {
r := & discoveryResolver {
w : w ,
w : w ,
cc : cc ,
cc : cc ,
ctx : ctx ,
ctx : ctx ,
cancel : cancel ,
cancel : cancel ,
log : log . NewHelper ( b . logger ) ,
log : log . NewHelper ( b . logger ) ,
insecure : b . insecure ,
insecure : b . insecure ,
debugLogDisabled : b . debugLogDisabled ,
}
}
go r . watch ( )
go r . watch ( )
return r , nil
return r , nil