-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Bump Go version to 1.23 2. Fix skipping code error in test 3. Fix dependency
- Loading branch information
Showing
36 changed files
with
756 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build go1.20 | ||
// +build go1.20 | ||
//go:build go1.23 | ||
// +build go1.23 | ||
|
||
package goredis8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build go1.20 | ||
// +build go1.20 | ||
//go:build go1.23 | ||
// +build go1.23 | ||
|
||
package gorm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package mongo | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/mongo" | ||
|
||
"github.com/avito-tech/go-transaction-manager/trm/v2" | ||
trmcontext "github.com/avito-tech/go-transaction-manager/trm/v2/context" | ||
) | ||
|
||
// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey. | ||
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager) | ||
|
||
// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr. | ||
type CtxGetter struct { | ||
ctxManager trm.СtxManager | ||
} | ||
|
||
// NewCtxGetter returns *CtxGetter to get Tr from context.Context. | ||
func NewCtxGetter(c trm.СtxManager) *CtxGetter { | ||
return &CtxGetter{ctxManager: c} | ||
} | ||
|
||
// DefaultTrOrDB returns mongo.Session from context.Context or DB(mongo.Session) otherwise. | ||
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db mongo.Session) mongo.Session { | ||
if tr := c.ctxManager.Default(ctx); tr != nil { | ||
return c.convert(tr) | ||
} | ||
|
||
return db | ||
} | ||
|
||
// TrOrDB returns mongo.Session from context.Context by trm.CtxKey or DB(mongo.Session) otherwise. | ||
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db mongo.Session) mongo.Session { | ||
if tr := c.ctxManager.ByKey(ctx, key); tr != nil { | ||
return c.convert(tr) | ||
} | ||
|
||
return db | ||
} | ||
|
||
func (c *CtxGetter) convert(tr trm.Transaction) mongo.Session { | ||
if tx, ok := tr.Transaction().(mongo.Session); ok { | ||
return tx | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.