Skip to content

Commit a7970ff

Browse files
authored
Merge pull request #267 from devfeel/aicode-lint-fixes-v2
fix: resolve golangci-lint issues v2
2 parents 5f7109a + c2cf85a commit a7970ff

File tree

9 files changed

+13
-40
lines changed

9 files changed

+13
-40
lines changed

cache/redis/cache_redis.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,8 @@ func (ca *RedisCache) GetInt(key string) (int, error) {
7171
v, err := ca.GetString(key)
7272
if err != nil || v == "" {
7373
return 0, err
74-
} else {
75-
i, e := strconv.Atoi(v)
76-
if e != nil {
77-
return 0, err
78-
} else {
79-
return i, nil
80-
}
8174
}
75+
return strconv.Atoi(v)
8276
}
8377

8478
// returns value int64 format by given key
@@ -87,14 +81,8 @@ func (ca *RedisCache) GetInt64(key string) (int64, error) {
8781
v, err := ca.GetString(key)
8882
if err != nil || v == "" {
8983
return ZeroInt64, err
90-
} else {
91-
i, e := strconv.ParseInt(v, 10, 64)
92-
if e != nil {
93-
return ZeroInt64, err
94-
} else {
95-
return i, nil
96-
}
9784
}
85+
return strconv.ParseInt(v, 10, 64)
9886
}
9987

10088
// Set cache to redis.

cache/runtime/cache_runtime.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ func (ca *RuntimeCache) GetString(key string) (string, error) {
6666
v, err := ca.Get(key)
6767
if err != nil || v == nil {
6868
return "", err
69-
} else {
70-
return fmt.Sprint(v), nil
7169
}
70+
return fmt.Sprint(v), nil
7271
}
7372

7473
// returns value int format by given key
@@ -77,14 +76,8 @@ func (ca *RuntimeCache) GetInt(key string) (int, error) {
7776
v, err := ca.GetString(key)
7877
if err != nil || v == "" {
7978
return 0, err
80-
} else {
81-
i, e := strconv.Atoi(v)
82-
if e != nil {
83-
return 0, e
84-
} else {
85-
return i, nil
86-
}
8779
}
80+
return strconv.Atoi(v)
8881
}
8982

9083
// returns value int64 format by given key
@@ -93,14 +86,8 @@ func (ca *RuntimeCache) GetInt64(key string) (int64, error) {
9386
v, err := ca.GetString(key)
9487
if err != nil || v == "" {
9588
return ZeroInt64, nil
96-
} else {
97-
i, e := strconv.ParseInt(v, 10, 64)
98-
if e != nil {
99-
return ZeroInt64, e
100-
} else {
101-
return i, nil
102-
}
10389
}
90+
return strconv.ParseInt(v, 10, 64)
10491
}
10592

10693
// Set cache to runtime.

config/configs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
import (
44
"encoding/xml"
55
"errors"
6-
"io/ioutil"
6+
"os"
77

88
"github.com/devfeel/dotweb/core"
99
"github.com/devfeel/dotweb/framework/file"
@@ -264,7 +264,7 @@ func dealConfigDefaultSet(c *Config) {
264264
}
265265

266266
func initConfig(configFile string, ctType string, parser func([]byte, interface{}) error) (*Config, error) {
267-
content, err := ioutil.ReadFile(configFile)
267+
content, err := os.ReadFile(configFile)
268268
if err != nil {
269269
return nil, errors.New("DotWeb:Config:initConfig current cType:" + ctType + " config file [" + configFile + "] cannot be parsed - " + err.Error())
270270
}

config/configset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
import (
44
"encoding/xml"
55
"errors"
6-
"io/ioutil"
6+
"os"
77

88
"github.com/devfeel/dotweb/core"
99
)
@@ -39,7 +39,7 @@ func ParseConfigSetYaml(configFile string) (core.ConcurrenceMap, error) {
3939
}
4040

4141
func parseConfigSetFile(configFile string, confType string) (core.ConcurrenceMap, error) {
42-
content, err := ioutil.ReadFile(configFile)
42+
content, err := os.ReadFile(configFile)
4343
if err != nil {
4444
return nil, errors.New("DotWeb:Config:parseConfigSetFile 配置文件[" + configFile + ", " + confType + "]无法解析 - " + err.Error())
4545
}

request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotweb
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net"
66
"net/http"
77
"net/url"
@@ -159,7 +159,7 @@ func (req *Request) PostBody() []byte {
159159
req.Body = http.MaxBytesReader(req.httpCtx.Response().Writer(), req.Body, req.httpApp().Config.Server.MaxBodySize)
160160
}
161161
}
162-
bts, err := ioutil.ReadAll(req.Body)
162+
bts, err := io.ReadAll(req.Body)
163163
if err != nil {
164164
//if err, panic it
165165
panic(err)

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func checkIsWebSocketRequest(req *http.Request) bool {
541541

542542
// check request is startwith /debug/
543543
func checkIsDebugRequest(req *http.Request) bool {
544-
if strings.Index(req.RequestURI, "/debug/") == 0 {
544+
if strings.HasPrefix(req.RequestURI, "/debug/") {
545545
return true
546546
}
547547
return false

tree.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func min(a, b int) int {
1717
return b
1818
}
1919

20-
const maxParamCount uint8 = ^uint8(0)
2120

2221
func countParams(path string) uint8 {
2322
var n uint

uploadfile.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type UploadFile struct {
1919
fileExt string // file extensions
2020
fileName string
2121
randomFileName string
22-
fileSize int64
2322
}
2423

2524
func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFile {

utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/url"
1010
"strings"

0 commit comments

Comments
 (0)