commit
877c565a9c
@ -23,6 +23,7 @@
|
|||||||
- Fix 4451: support QueryExecutor interface. [4461](https://github.com/beego/beego/pull/4461)
|
- Fix 4451: support QueryExecutor interface. [4461](https://github.com/beego/beego/pull/4461)
|
||||||
- Add some testing scripts [4461](https://github.com/beego/beego/pull/4461)
|
- Add some testing scripts [4461](https://github.com/beego/beego/pull/4461)
|
||||||
- Refactor httplib: Move debug code to a filter [4440](https://github.com/beego/beego/issues/4440)
|
- Refactor httplib: Move debug code to a filter [4440](https://github.com/beego/beego/issues/4440)
|
||||||
|
- fix: code quality issues [4513](https://github.com/beego/beego/pull/4513)
|
||||||
|
|
||||||
|
|
||||||
## Fix Sonar
|
## Fix Sonar
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
package httplib
|
package httplib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -261,7 +262,7 @@ func TestToFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.Remove(f)
|
defer os.Remove(f)
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := ioutil.ReadFile(f)
|
||||||
if n := strings.Index(string(b), "origin"); n == -1 {
|
if n := bytes.Index(b, []byte("origin")); n == -1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,7 +276,7 @@ func TestToFileDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll("./files")
|
defer os.RemoveAll("./files")
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := ioutil.ReadFile(f)
|
||||||
if n := strings.Index(string(b), "origin"); n == -1 {
|
if n := bytes.Index(b, []byte("origin")); n == -1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,7 +195,7 @@ func snakeStringWithAcronym(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return strings.ToLower(string(data[:]))
|
return strings.ToLower(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// snake string, XxYy to xx_yy , XxYY to xx_y_y
|
// snake string, XxYy to xx_yy , XxYY to xx_y_y
|
||||||
@ -213,7 +213,7 @@ func snakeString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return strings.ToLower(string(data[:]))
|
return strings.ToLower(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNameStrategy set different name strategy
|
// SetNameStrategy set different name strategy
|
||||||
@ -241,7 +241,7 @@ func camelString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return string(data[:])
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
type argString []string
|
type argString []string
|
||||||
|
|||||||
4
client/cache/memory.go
vendored
4
client/cache/memory.go
vendored
@ -42,7 +42,7 @@ func (mi *MemoryItem) isExpire() bool {
|
|||||||
if mi.lifespan == 0 {
|
if mi.lifespan == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return time.Now().Sub(mi.createdTime) > mi.lifespan
|
return time.Since(mi.createdTime) > mi.lifespan
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryCache is a memory cache adapter.
|
// MemoryCache is a memory cache adapter.
|
||||||
@ -66,7 +66,7 @@ func (bc *MemoryCache) Get(ctx context.Context, key string) (interface{}, error)
|
|||||||
bc.RLock()
|
bc.RLock()
|
||||||
defer bc.RUnlock()
|
defer bc.RUnlock()
|
||||||
if itm, ok :=
|
if itm, ok :=
|
||||||
bc.items[key]; ok {
|
bc.items[key]; ok {
|
||||||
if itm.isExpire() {
|
if itm.isExpire() {
|
||||||
return nil, ErrKeyExpired
|
return nil, ErrKeyExpired
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
package httplib
|
package httplib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -259,7 +260,7 @@ func TestToFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.Remove(f)
|
defer os.Remove(f)
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := ioutil.ReadFile(f)
|
||||||
if n := strings.Index(string(b), "origin"); n == -1 {
|
if n := bytes.Index(b, []byte("origin")); n == -1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,7 +274,7 @@ func TestToFileDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll("./files")
|
defer os.RemoveAll("./files")
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := ioutil.ReadFile(f)
|
||||||
if n := strings.Index(string(b), "origin"); n == -1 {
|
if n := bytes.Index(b, []byte("origin")); n == -1 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ func (builder *FilterChainBuilder) report(ctx context.Context, inv *orm.Invocati
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (builder *FilterChainBuilder) reportTxn(ctx context.Context, inv *orm.Invocation) {
|
func (builder *FilterChainBuilder) reportTxn(ctx context.Context, inv *orm.Invocation) {
|
||||||
dur := time.Now().Sub(inv.TxStartTime) / time.Millisecond
|
dur := time.Since(inv.TxStartTime) / time.Millisecond
|
||||||
summaryVec.WithLabelValues(inv.Method, inv.TxName,
|
summaryVec.WithLabelValues(inv.Method, inv.TxName,
|
||||||
strconv.FormatBool(inv.InsideTx), inv.TxName).Observe(float64(dur))
|
strconv.FormatBool(inv.InsideTx), inv.TxName).Observe(float64(dur))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ func NewLog(out io.Writer) *Log {
|
|||||||
|
|
||||||
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
|
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
|
||||||
var logMap = make(map[string]interface{})
|
var logMap = make(map[string]interface{})
|
||||||
sub := time.Now().Sub(t) / 1e5
|
sub := time.Since(t) / 1e5
|
||||||
elsp := float64(int(sub)) / 10.0
|
elsp := float64(int(sub)) / 10.0
|
||||||
logMap["cost_time"] = elsp
|
logMap["cost_time"] = elsp
|
||||||
flag := " OK"
|
flag := " OK"
|
||||||
|
|||||||
@ -228,7 +228,7 @@ func snakeStringWithAcronym(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return strings.ToLower(string(data[:]))
|
return strings.ToLower(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// snake string, XxYy to xx_yy , XxYY to xx_y_y
|
// snake string, XxYy to xx_yy , XxYY to xx_y_y
|
||||||
@ -246,7 +246,7 @@ func snakeString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return strings.ToLower(string(data[:]))
|
return strings.ToLower(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNameStrategy set different name strategy
|
// SetNameStrategy set different name strategy
|
||||||
@ -274,7 +274,7 @@ func camelString(s string) string {
|
|||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
return string(data[:])
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
type argString []string
|
type argString []string
|
||||||
|
|||||||
@ -108,7 +108,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) {
|
|||||||
|
|
||||||
if gcstats.NumGC > 0 {
|
if gcstats.NumGC > 0 {
|
||||||
lastPause := gcstats.Pause[0]
|
lastPause := gcstats.Pause[0]
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
overhead := float64(gcstats.PauseTotal) / float64(elapsed) * 100
|
overhead := float64(gcstats.PauseTotal) / float64(elapsed) * 100
|
||||||
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
|
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) {
|
|||||||
utils.ToShortTimeFormat(gcstats.PauseQuantiles[99]))
|
utils.ToShortTimeFormat(gcstats.PauseQuantiles[99]))
|
||||||
} else {
|
} else {
|
||||||
// while GC has disabled
|
// while GC has disabled
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
|
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
|
||||||
|
|
||||||
fmt.Fprintf(w, "Alloc:%s Sys:%s Alloc(Rate):%s/s\n",
|
fmt.Fprintf(w, "Alloc:%s Sys:%s Alloc(Rate):%s/s\n",
|
||||||
|
|||||||
@ -143,7 +143,7 @@ func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map
|
|||||||
rHeader = strings.TrimSpace(rHeader)
|
rHeader = strings.TrimSpace(rHeader)
|
||||||
lookupLoop:
|
lookupLoop:
|
||||||
for _, allowedHeader := range o.AllowHeaders {
|
for _, allowedHeader := range o.AllowHeaders {
|
||||||
if strings.ToLower(rHeader) == strings.ToLower(allowedHeader) {
|
if strings.EqualFold(rHeader, allowedHeader) {
|
||||||
allowed = append(allowed, rHeader)
|
allowed = append(allowed, rHeader)
|
||||||
break lookupLoop
|
break lookupLoop
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,9 +211,7 @@ func (fp *FileProvider) SessionGC(context.Context) {
|
|||||||
// it walks save path to count files.
|
// it walks save path to count files.
|
||||||
func (fp *FileProvider) SessionAll(context.Context) int {
|
func (fp *FileProvider) SessionAll(context.Context) int {
|
||||||
a := &activeSession{}
|
a := &activeSession{}
|
||||||
err := filepath.Walk(fp.savePath, func(path string, f os.FileInfo, err error) error {
|
err := filepath.Walk(fp.savePath, a.visit)
|
||||||
return a.visit(path, f, err)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SLogger.Printf("filepath.Walk() returned %v\n", err)
|
SLogger.Printf("filepath.Walk() returned %v\n", err)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -202,9 +202,7 @@ func BuildTemplate(dir string, files ...string) error {
|
|||||||
root: dir,
|
root: dir,
|
||||||
files: make(map[string][]string),
|
files: make(map[string][]string),
|
||||||
}
|
}
|
||||||
err = Walk(fs, dir, func(path string, f os.FileInfo, err error) error {
|
err = Walk(fs, dir, self.visit)
|
||||||
return self.visit(path, f, err)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Walk() returned %v\n", err)
|
fmt.Printf("Walk() returned %v\n", err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -287,9 +287,7 @@ func _filePath(dir, name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assetFS() *assetfs.AssetFS {
|
func assetFS() *assetfs.AssetFS {
|
||||||
assetInfo := func(path string) (os.FileInfo, error) {
|
assetInfo := os.Stat
|
||||||
return os.Stat(path)
|
|
||||||
}
|
|
||||||
for k := range _bintree.Children {
|
for k := range _bintree.Children {
|
||||||
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: assetInfo, Prefix: k}
|
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: assetInfo, Prefix: k}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user