File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -132,9 +132,6 @@ linters-settings:
132
132
linters :
133
133
enable-all : true
134
134
disable :
135
- - rowserrcheck # is disabled because of generics
136
- - sqlclosecheck # is disabled because of generics
137
- - wastedassign # is disabled because of generics
138
135
- exportloopref # is deprecated (since v1.60.2)
139
136
- dupword
140
137
- wrapcheck
@@ -144,10 +141,9 @@ linters:
144
141
145
142
issues :
146
143
exclude :
147
- - " don't use ALL_CAPS in Go names; use CamelCase" # golint
144
+ - " don't use ALL_CAPS in Go names; use CamelCase" # revive
148
145
- " ST1003: should not use ALL_CAPS in Go names; use CamelCase instead" # stylecheck
149
146
- " DefaultSettings`? is a global variable" # gochecknoglobals
150
- - " are|is missing in" # exhaustivestruct # v1.33
151
147
exclude-dirs :
152
148
- vendor/
153
149
exclude-files :
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
4
4
** ATTN** : This project uses [ semantic versioning] ( http://semver.org/ ) .
5
5
6
6
## [ Unreleased]
7
+ ### Added
8
+ - Added maxCommandLen setting and SetMaxCommandLen function.
7
9
8
10
## [ v1.4.0] - 2024-11-16
9
11
### Fixed
Original file line number Diff line number Diff line change @@ -4,14 +4,16 @@ import "time"
4
4
5
5
// Settings contains option to Conn.
6
6
type Settings struct {
7
- dialTimeout time.Duration
8
- deadline time.Duration
7
+ dialTimeout time.Duration
8
+ deadline time.Duration
9
+ maxCommandLen int
9
10
}
10
11
11
12
// DefaultSettings provides default deadline settings to Conn.
12
13
var DefaultSettings = Settings {
13
- dialTimeout : DefaultDialTimeout ,
14
- deadline : DefaultDeadline ,
14
+ dialTimeout : DefaultDialTimeout ,
15
+ deadline : DefaultDeadline ,
16
+ maxCommandLen : DefaultMaxCommandLen ,
15
17
}
16
18
17
19
// Option allows to inject settings to Settings.
@@ -30,3 +32,10 @@ func SetDeadline(timeout time.Duration) Option {
30
32
s .deadline = timeout
31
33
}
32
34
}
35
+
36
+ // SetMaxCommandLen injects maxCommandLen to Settings.
37
+ func SetMaxCommandLen (maxCommandLen int ) Option {
38
+ return func (s * Settings ) {
39
+ s .maxCommandLen = maxCommandLen
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -17,9 +17,9 @@ const (
17
17
// DefaultDeadline provides default deadline to tcp read/write operations.
18
18
DefaultDeadline = 5 * time .Second
19
19
20
- // MaxCommandLen is an artificial restriction, but it will help in case of random
20
+ // DefaultMaxCommandLen is an artificial restriction, but it will help in case of random
21
21
// large queries.
22
- MaxCommandLen = 1000
22
+ DefaultMaxCommandLen = 1000
23
23
24
24
// SERVERDATA_AUTH is the first packet sent by the client,
25
25
// which is used to authenticate the conn with the server.
@@ -148,7 +148,7 @@ func (c *Conn) Execute(command string) (string, error) {
148
148
return "" , ErrCommandEmpty
149
149
}
150
150
151
- if len (command ) > MaxCommandLen {
151
+ if c . settings . maxCommandLen > 0 && len (command ) > c . settings . maxCommandLen {
152
152
return "" , ErrCommandTooLong
153
153
}
154
154
You can’t perform that action at this time.
0 commit comments