优化Codes2

This commit is contained in:
injoyai
2025-11-17 11:04:55 +08:00
parent fcb6c995ad
commit 5fd492e881
2 changed files with 69 additions and 7 deletions

View File

@@ -50,6 +50,12 @@ func WithRetry(retry int) Codes2Option {
}
}
func WithClient(c *Client) Codes2Option {
return func(cs *Codes2) {
cs.c = c
}
}
func WithDial(dial ios.DialFunc, op ...client.Option) Codes2Option {
return func(c *Codes2) {
c.dial = dial
@@ -84,9 +90,11 @@ func NewCodes2(op ...Codes2Option) (*Codes2, error) {
var err error
// 初始化连接
cs.c, err = DialWith(cs.dial, cs.dialOption...)
if err != nil {
return nil, err
if cs.c == nil {
cs.c, err = DialWith(cs.dial, cs.dialOption...)
if err != nil {
return nil, err
}
}
// 初始化数据库