Browse Source

去掉多余的锁

pull/119/head
zhangxin 3 years ago
parent
commit
068019d612
3 changed files with 0 additions and 12 deletions
  1. +0
    -4
      infra/logger/console.go
  2. +0
    -4
      infra/logger/file.go
  3. +0
    -4
      infra/logger/mongo.go

+ 0
- 4
infra/logger/console.go View File

@ -4,10 +4,8 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
"sync"
)
var cLock sync.Mutex
var consoleLogCore *zap.Logger
type consoleLogger struct {
@ -15,8 +13,6 @@ type consoleLogger struct {
}
func NewConsoleDriver(config console) (driver, error) {
cLock.Lock()
defer cLock.Unlock()
if consoleLogCore == nil {
coreEncoder := zap.NewProductionEncoderConfig()
coreEncoder.EncodeLevel = zapcore.CapitalLevelEncoder


+ 0
- 4
infra/logger/file.go View File

@ -4,12 +4,10 @@ import (
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"sync"
)
var (
fileLogCore *zap.Logger
fLock sync.Mutex
)
type fileDriver struct {
@ -18,8 +16,6 @@ type fileDriver struct {
}
func NewFileDriver(config file, level int) (driver, error) {
fLock.Lock()
defer fLock.Unlock()
if fileLogCore == nil {
lumberjackLogger := &lumberjack.Logger{
Filename: config.Filename,


+ 0
- 4
infra/logger/mongo.go View File

@ -5,18 +5,14 @@ import (
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"sync"
"time"
)
var (
collection *mongo.Collection
mLock sync.Mutex
)
func NewMongoDriver(config db, level int) (driver, error) {
mLock.Lock()
defer mLock.Unlock()
if collection == nil {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%d", config.Host, config.Port)))


Loading…
Cancel
Save