fix service client issue

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-19 19:29:45 +03:00
parent 0d3e8255ba
commit 11f417c788
2 changed files with 13 additions and 2 deletions

View File

@ -1,2 +1,2 @@
# micro-logger-service
# micro-config-service

View File

@ -6,6 +6,7 @@ import (
"github.com/imdario/mergo"
pb "github.com/unistack-org/micro-config-service/v3/proto"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/config"
rutil "github.com/unistack-org/micro/v3/util/reflect"
)
@ -29,16 +30,26 @@ func (c *serviceConfig) Init(opts ...config.Option) error {
o(&c.opts)
}
var cli client.Client
if c.opts.Context != nil {
if v, ok := c.opts.Context.Value(serviceKey{}).(string); ok {
if v, ok := c.opts.Context.Value(serviceKey{}).(string); ok && v != "" {
c.service = v
}
if v, ok := c.opts.Context.Value(clientKey{}).(client.Client); ok {
cli = v
}
}
if cli == nil {
return fmt.Errorf("missing Client option")
}
if c.service == "" {
return fmt.Errorf("missing Service option")
}
c.client = pb.NewConfigService(c.service, cli)
return nil
}