Upgrade golangci-lint and fixes some linting errors. (#22909)
Example: https://play.golang.org/p/cfPIPG3BwjJ
This commit is contained in:
@@ -28,7 +28,7 @@ func newSession() *DBSession {
|
||||
}
|
||||
|
||||
func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DBSession, error) {
|
||||
value := ctx.Value(ContextSessionName)
|
||||
value := ctx.Value(ContextSessionKey{})
|
||||
var sess *DBSession
|
||||
sess, ok := value.(*DBSession)
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ var (
|
||||
sqlog log.Logger = log.New("sqlstore")
|
||||
)
|
||||
|
||||
const ContextSessionName = "db-session"
|
||||
// ContextSessionKey is used as key to save values in `context.Context`
|
||||
type ContextSessionKey struct{}
|
||||
|
||||
func init() {
|
||||
// This change will make xorm use an empty default schema for postgres and
|
||||
|
||||
@@ -22,7 +22,7 @@ func (ss *SqlStore) InTransaction(ctx context.Context, fn func(ctx context.Conte
|
||||
|
||||
func (ss *SqlStore) inTransactionWithRetry(ctx context.Context, fn func(ctx context.Context) error, retry int) error {
|
||||
return inTransactionWithRetryCtx(ctx, ss.engine, func(sess *DBSession) error {
|
||||
withValue := context.WithValue(ctx, ContextSessionName, sess)
|
||||
withValue := context.WithValue(ctx, ContextSessionKey{}, sess)
|
||||
return fn(withValue)
|
||||
}, retry)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ var ErrProvokedError = errors.New("testing error")
|
||||
func TestTransaction(t *testing.T) {
|
||||
ss := InitTestDB(t)
|
||||
|
||||
Convey("InTransaction asdf asdf", t, func() {
|
||||
Convey("InTransaction", t, func() {
|
||||
cmd := &models.AddApiKeyCommand{Key: "secret-key", Name: "key", OrgId: 1}
|
||||
|
||||
err := AddApiKey(cmd)
|
||||
|
||||
@@ -455,8 +455,8 @@ func TestUserDataAccess(t *testing.T) {
|
||||
var err error
|
||||
createUserCmd := &models.CreateUserCommand{
|
||||
Email: fmt.Sprint("admin", "@test.com"),
|
||||
Name: fmt.Sprint("admin"),
|
||||
Login: fmt.Sprint("admin"),
|
||||
Name: "admin",
|
||||
Login: "admin",
|
||||
IsAdmin: true,
|
||||
}
|
||||
err = CreateUser(context.Background(), createUserCmd)
|
||||
|
||||
Reference in New Issue
Block a user