fix init
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
7314f6829d
commit
2fdd6dfdc3
31
service.go
31
service.go
@ -2,19 +2,22 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
pb "github.com/unistack-org/micro-logger-service/v3/proto"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
)
|
||||
|
||||
type serviceLogger struct {
|
||||
opts logger.Options
|
||||
client pb.LoggerService
|
||||
store store.Store
|
||||
fields map[string]interface{}
|
||||
opts logger.Options
|
||||
service string
|
||||
client pb.LoggerService
|
||||
store store.Store
|
||||
fields map[string]interface{}
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Init(opts ...logger.Option) error {
|
||||
@ -22,6 +25,26 @@ func (l *serviceLogger) Init(opts ...logger.Option) error {
|
||||
o(&l.opts)
|
||||
}
|
||||
|
||||
var cli client.Client
|
||||
if l.opts.Context != nil {
|
||||
if v, ok := l.opts.Context.Value(clientKey{}).(client.Client); ok && v != nil {
|
||||
cli = v
|
||||
}
|
||||
if v, ok := l.opts.Context.Value(serviceKey{}).(string); ok && v != "" {
|
||||
l.service = v
|
||||
}
|
||||
}
|
||||
|
||||
if l.service == "" {
|
||||
return fmt.Errorf("missing Service option")
|
||||
}
|
||||
|
||||
if cli == nil {
|
||||
return fmt.Errorf("missing Client option")
|
||||
}
|
||||
|
||||
l.client = pb.NewLoggerService(l.service, cli)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user