service and client implements last grpc server and client interfaces, improved errors, add signals handling

This commit is contained in:
2020-11-27 14:00:45 +01:00
parent c1d38dfbd0
commit a6696b1d39
13 changed files with 839 additions and 689 deletions

45
logger/context.go Normal file
View File

@ -0,0 +1,45 @@
package logger
import (
"context"
"sync"
"github.com/sirupsen/logrus"
)
var (
defaultLogger Logger
mu sync.RWMutex
)
type log struct{}
func init() {
defaultLogger = &logger{FieldLogger: logrus.New()}
}
func SetDefault(logger Logger) {
mu.Lock()
defer mu.Unlock()
defaultLogger = logger
}
func Set(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, log{}, logger)
}
func From(ctx context.Context) Logger {
log, ok := ctx.Value(log{}).(Logger)
if ok {
return log
}
if defaultLogger != nil {
return defaultLogger
}
logr := New()
mu.Lock()
defer mu.Unlock()
defaultLogger = logr
return defaultLogger
}