Inappropriate key in call to context.WithValue GO-W5003
Bug risk
Major
6 months ago2 years old
should not use built-in type string as key for value; define your own type to avoid collisions
167		}
168	})
169
170	ctx := context.WithValue(context.Background(), TxNameKey, "do tx name")171	err = od.DoTxWithCtxAndOpts(ctx, nil, func(c context.Context, txOrm TxOrmer) error {
172		return nil
173	})
should not use built-in type string as key for value; define your own type to avoid collisions
 86	assert.NotNil(t, err)
 87	assert.Equal(t, "commit", err.Error())
 88
 89	ctx = context.WithValue(context.Background(), TxNameKey, "Rollback_tx") 90	to, err = od.BeginWithCtxAndOpts(ctx, nil)
 91	assert.True(t, validateBeginResult(t, to, err))
 92
should not use built-in type string as key for value; define your own type to avoid collisions
 78	to, err = od.BeginWithOpts(nil)
 79	assert.True(t, validateBeginResult(t, to, err))
 80
 81	ctx := context.WithValue(context.Background(), TxNameKey, "Commit_tx") 82	to, err = od.BeginWithCtx(ctx)
 83	assert.True(t, validateBeginResult(t, to, err))
 84
should not use built-in type string as key for value; define your own type to avoid collisions
45}
46
47func CtxWithMock(ctx context.Context, mock ...*Mock) context.Context {
48	return context.WithValue(ctx, mockCtxKey, mock)49}
50
51func mockFromCtx(ctx context.Context) []*Mock {