diff --git a/CHANGELOG.md b/CHANGELOG.md index 223e2c29..65e7aa44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,9 @@ # developing -- Fix lint and format code in adapter/config dir [4646](https://github.com/beego/beego/pull/4646) - Add http client and option func. [4455](https://github.com/beego/beego/issues/4455) - Add: Convenient way to generate mock object [4620](https://github.com/beego/beego/issues/4620) -- Fix lint and format code in adapter/context dir [4647](https://github.com/beego/beego/pull/4647) - Infra: use dependabot to update dependencies. [4623](https://github.com/beego/beego/pull/4623) - Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619) -- Fix lint and format code in adapter/httplib dir [4648](https://github.com/beego/beego/pull/4648) - Chore: format code. [4615](https://github.com/beego/beego/pull/4615) - Test on Go v1.15.x & v1.16.x. [4614](https://github.com/beego/beego/pull/4614) - Env: non-empty GOBIN & GOPATH. [4613](https://github.com/beego/beego/pull/4613) @@ -54,7 +51,6 @@ - Init exceptMethod by using reflection. [4583](https://github.com/beego/beego/pull/4583) - Deprecated BeeMap and replace all usage with `sync.map` [4616](https://github.com/beego/beego/pull/4616) - TaskManager support graceful shutdown [4635](https://github.com/beego/beego/pull/4635) -- Fix lint and format code in adapter/cache dir [4645](https://github.com/beego/beego/pull/4645) ## Fix Sonar @@ -69,3 +65,8 @@ - [4651](https://github.com/beego/beego/pull/4651) - [4644](https://github.com/beego/beego/pull/4644) +- [4645](https://github.com/beego/beego/pull/4645) +- [4646](https://github.com/beego/beego/pull/4646) +- [4647](https://github.com/beego/beego/pull/4647) +- [4648](https://github.com/beego/beego/pull/4648) +- [4649](https://github.com/beego/beego/pull/4649) diff --git a/adapter/app.go b/adapter/app.go index 8502256b..2a5ff123 100644 --- a/adapter/app.go +++ b/adapter/app.go @@ -22,10 +22,8 @@ import ( "github.com/beego/beego/v2/server/web/context" ) -var ( - // BeeApp is an application instance - BeeApp *App -) +// BeeApp is an application instance +var BeeApp *App func init() { // create beego application diff --git a/adapter/beego.go b/adapter/beego.go index 331aa786..08eb1e72 100644 --- a/adapter/beego.go +++ b/adapter/beego.go @@ -36,10 +36,6 @@ type M web.M // Hook function to run type hookfunc func() error -var ( - hooks = make([]hookfunc, 0) // hook function slice to store the hookfunc -) - // AddAPPStartHook is used to register the hookfunc // The hookfuncs will run in beego.Run() // such as initiating session , starting middleware , building template, starting admin control and so on. diff --git a/adapter/controller.go b/adapter/controller.go index 840abb48..6d2d5f64 100644 --- a/adapter/controller.go +++ b/adapter/controller.go @@ -48,9 +48,11 @@ type ControllerCommentsSlice web.ControllerCommentsSlice func (p ControllerCommentsSlice) Len() int { return (web.ControllerCommentsSlice)(p).Len() } + func (p ControllerCommentsSlice) Less(i, j int) bool { return (web.ControllerCommentsSlice)(p).Less(i, j) } + func (p ControllerCommentsSlice) Swap(i, j int) { (web.ControllerCommentsSlice)(p).Swap(i, j) } diff --git a/adapter/orm/db.go b/adapter/orm/db.go index 3cdd33cd..c1d1fe92 100644 --- a/adapter/orm/db.go +++ b/adapter/orm/db.go @@ -18,7 +18,5 @@ import ( "github.com/beego/beego/v2/client/orm" ) -var ( - // ErrMissPK missing pk error - ErrMissPK = orm.ErrMissPK -) +// ErrMissPK missing pk error +var ErrMissPK = orm.ErrMissPK diff --git a/adapter/orm/query_setter_adapter.go b/adapter/orm/query_setter_adapter.go deleted file mode 100644 index edea0a15..00000000 --- a/adapter/orm/query_setter_adapter.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package orm - -import ( - "github.com/beego/beego/v2/client/orm" -) - -type baseQuerySetter struct { -} - -const shouldNotInvoke = "you should not invoke this method." - -func (b *baseQuerySetter) ForceIndex(indexes ...string) orm.QuerySeter { - panic(shouldNotInvoke) -} - -func (b *baseQuerySetter) UseIndex(indexes ...string) orm.QuerySeter { - panic(shouldNotInvoke) -} - -func (b *baseQuerySetter) IgnoreIndex(indexes ...string) orm.QuerySeter { - panic(shouldNotInvoke) -} diff --git a/adapter/session/redis_sentinel/sess_redis_sentinel_test.go b/adapter/session/redis_sentinel/sess_redis_sentinel_test.go index b08d0256..2d381af6 100644 --- a/adapter/session/redis_sentinel/sess_redis_sentinel_test.go +++ b/adapter/session/redis_sentinel/sess_redis_sentinel_test.go @@ -72,5 +72,4 @@ func TestRedisSentinel(t *testing.T) { assert.Nil(t, password) sess.SessionRelease(w) - } diff --git a/adapter/session/sess_file_test.go b/adapter/session/sess_file_test.go index 4cec8341..a3e3d0b9 100644 --- a/adapter/session/sess_file_test.go +++ b/adapter/session/sess_file_test.go @@ -22,14 +22,14 @@ import ( "time" ) -const sid = "Session_id" -const sidNew = "Session_id_new" -const sessionPath = "./_session_runtime" - -var ( - mutex sync.Mutex +const ( + sid = "Session_id" + sidNew = "Session_id_new" + sessionPath = "./_session_runtime" ) +var mutex sync.Mutex + func TestFileProviderSessionExist(t *testing.T) { mutex.Lock() defer mutex.Unlock() diff --git a/adapter/templatefunc.go b/adapter/templatefunc.go index 808539e7..c5574d32 100644 --- a/adapter/templatefunc.go +++ b/adapter/templatefunc.go @@ -118,7 +118,6 @@ func AssetsJs(text string) template.HTML { // AssetsCSS returns stylesheet link tag with src string. func AssetsCSS(text string) template.HTML { - text = "" return template.HTML(text) diff --git a/adapter/templatefunc_test.go b/adapter/templatefunc_test.go index c12efd7e..b3d5e968 100644 --- a/adapter/templatefunc_test.go +++ b/adapter/templatefunc_test.go @@ -79,7 +79,6 @@ func TestHtmlunquote(t *testing.T) { h := `<' ”“&">` s := `<' ”“&">` assert.Equal(t, s, Htmlunquote(h)) - } func TestParseForm(t *testing.T) { @@ -234,5 +233,4 @@ func TestMapGet(t *testing.T) { res, err = MapGet(m5, 5, 4, 3, 2, 1) assert.Nil(t, err) assert.Nil(t, res) - } diff --git a/adapter/testing/client.go b/adapter/testing/client.go index 356a0f68..a773c9a6 100644 --- a/adapter/testing/client.go +++ b/adapter/testing/client.go @@ -14,12 +14,7 @@ package testing -import ( - "github.com/beego/beego/v2/client/httplib/testing" -) - -var port = "" -var baseURL = "http://localhost:" +import "github.com/beego/beego/v2/client/httplib/testing" // TestHTTPRequest beego test request client type TestHTTPRequest testing.TestHTTPRequest diff --git a/adapter/toolbox/profile.go b/adapter/toolbox/profile.go index 15d7010a..00b0eef7 100644 --- a/adapter/toolbox/profile.go +++ b/adapter/toolbox/profile.go @@ -16,19 +16,10 @@ package toolbox import ( "io" - "os" - "time" "github.com/beego/beego/v2/core/admin" ) -var startTime = time.Now() -var pid int - -func init() { - pid = os.Getpid() -} - // ProcessInput parse input command string func ProcessInput(input string, w io.Writer) { admin.ProcessInput(input, w) diff --git a/adapter/toolbox/task.go b/adapter/toolbox/task.go index 7b7cd68a..199956f8 100644 --- a/adapter/toolbox/task.go +++ b/adapter/toolbox/task.go @@ -80,7 +80,6 @@ type Task struct { // NewTask add new task with name, time and func func NewTask(tname string, spec string, f TaskFunc) *Task { - task := task.NewTask(tname, spec, func(ctx context.Context) error { return f() }) @@ -98,7 +97,6 @@ func (t *Task) GetSpec() string { // GetStatus get current task status func (t *Task) GetStatus() string { - t.initDelegate() return t.delegate.GetStatus(context.Background()) @@ -222,7 +220,6 @@ type MapSorter task.MapSorter // NewMapSorter create new tasker map func NewMapSorter(m map[string]Tasker) *MapSorter { - newTaskerMap := make(map[string]task.Tasker, len(m)) for key, value := range m { @@ -249,6 +246,7 @@ func (ms *MapSorter) Less(i, j int) bool { } return ms.Vals[i].GetNext(context.Background()).Before(ms.Vals[j].GetNext(context.Background())) } + func (ms *MapSorter) Swap(i, j int) { ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i] ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i] diff --git a/adapter/utils/captcha/captcha.go b/adapter/utils/captcha/captcha.go index 741be9a5..7cdcab2d 100644 --- a/adapter/utils/captcha/captcha.go +++ b/adapter/utils/captcha/captcha.go @@ -69,9 +69,7 @@ import ( beecontext "github.com/beego/beego/v2/server/web/context" ) -var ( - defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} -) +var defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} const ( // default captcha attributes diff --git a/adapter/utils/debug_test.go b/adapter/utils/debug_test.go index efb8924e..a748d20a 100644 --- a/adapter/utils/debug_test.go +++ b/adapter/utils/debug_test.go @@ -28,8 +28,8 @@ func TestPrint(t *testing.T) { } func TestPrintPoint(t *testing.T) { - var v1 = new(mytype) - var v2 = new(mytype) + v1 := new(mytype) + v2 := new(mytype) v1.prev = nil v1.next = v2 diff --git a/adapter/utils/slice.go b/adapter/utils/slice.go index cdbfcca8..082b22ce 100644 --- a/adapter/utils/slice.go +++ b/adapter/utils/slice.go @@ -19,6 +19,7 @@ import ( ) type reducetype func(interface{}) interface{} + type filtertype func(interface{}) bool // InSlice checks given string in string slice or not. diff --git a/adapter/validation/util.go b/adapter/validation/util.go index 502be750..5ff43ebc 100644 --- a/adapter/validation/util.go +++ b/adapter/validation/util.go @@ -27,9 +27,7 @@ const ( LabelTag = validation.LabelTag ) -var ( - ErrInt64On32 = validation.ErrInt64On32 -) +var ErrInt64On32 = validation.ErrInt64On32 // CustomFunc is for custom validate function type CustomFunc func(v *Validation, obj interface{}, key string) diff --git a/adapter/validation/validation_test.go b/adapter/validation/validation_test.go index 2e29b641..547e8635 100644 --- a/adapter/validation/validation_test.go +++ b/adapter/validation/validation_test.go @@ -50,7 +50,6 @@ func TestMin(t *testing.T) { assert.False(t, valid.Min(-1, 0, "min0").Ok) assert.True(t, valid.Min(1, 0, "min0").Ok) - } func TestMax(t *testing.T) { @@ -502,5 +501,4 @@ func TestCanSkipAlso(t *testing.T) { assert.Nil(t, err) assert.True(t, b) - }