fix init
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
7314f6829d
commit
2fdd6dfdc3
23
service.go
23
service.go
@ -2,16 +2,19 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
pb "github.com/unistack-org/micro-logger-service/v3/proto"
|
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/logger"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"github.com/unistack-org/micro/v3/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type serviceLogger struct {
|
type serviceLogger struct {
|
||||||
opts logger.Options
|
opts logger.Options
|
||||||
|
service string
|
||||||
client pb.LoggerService
|
client pb.LoggerService
|
||||||
store store.Store
|
store store.Store
|
||||||
fields map[string]interface{}
|
fields map[string]interface{}
|
||||||
@ -22,6 +25,26 @@ func (l *serviceLogger) Init(opts ...logger.Option) error {
|
|||||||
o(&l.opts)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user