Skip to content

Commit 9d5e827

Browse files
committed
refactor internal/table/client and upload with off gocognit linter
1 parent c6ef237 commit 9d5e827

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Refactored `internal/table/client.go` and extract func `client.onCloseSession`
12
* Refactored `internal/decimal/decimal.go` and extract func `decimal.dotStringAnalysis`
23
* Refactored `internal/backoff/backoff_test.go` and extract func `backoff_test.checkExpWithAct` for compare
34
* Refactored `internal/xsql/dsn.go` and extract func `dsn.bindTablePathPrefixInConnectorOptions`

internal/table/client.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,7 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
173173
defer cancel()
174174
}
175175

176-
closeSession := func(s *session) {
177-
if s == nil {
178-
return
179-
}
180-
181-
closeSessionCtx := xcontext.WithoutDeadline(ctx)
182-
183-
if timeout := c.config.DeleteTimeout(); timeout > 0 {
184-
var cancel context.CancelFunc
185-
createSessionCtx, cancel = xcontext.WithTimeout(closeSessionCtx, timeout)
186-
defer cancel()
187-
}
188-
189-
_ = s.Close(closeSessionCtx)
190-
}
176+
closeSession := onCloseSession(ctx, createSessionCtx, c)
191177

192178
s, err = c.build(createSessionCtx)
193179

@@ -223,6 +209,25 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
223209
}
224210
}
225211

212+
// onCloseSession is a closure function that takes a session and performs the actions to close it.
213+
func onCloseSession(ctx, createSessionCtx context.Context, c *Client) func(s *session) {
214+
return func(s *session) {
215+
if s == nil {
216+
return
217+
}
218+
219+
closeSessionCtx := xcontext.WithoutDeadline(ctx)
220+
221+
if timeout := c.config.DeleteTimeout(); timeout > 0 {
222+
var cancel context.CancelFunc
223+
createSessionCtx, cancel = xcontext.WithTimeout(closeSessionCtx, timeout)
224+
defer cancel()
225+
}
226+
227+
_ = s.Close(closeSessionCtx)
228+
}
229+
}
230+
226231
func (c *Client) CreateSession(ctx context.Context, opts ...table.Option) (_ table.ClosableSession, err error) {
227232
if c == nil {
228233
return nil, xerrors.WithStackTrace(errNilClient)

0 commit comments

Comments
 (0)