Merge pull request #4649 from Loyalsoldier/adapter-fix-lint

Fix lint and format code in adapter dir
This commit is contained in:
Ming Deng 2021-06-06 21:45:19 +08:00 committed by GitHub
commit 75fdc048ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 24 additions and 90 deletions

View File

@ -1,12 +1,9 @@
# developing # 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 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) - 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) - 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) - 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) - 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) - 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) - 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) - 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) - 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) - 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 ## Fix Sonar
@ -69,3 +65,8 @@
- [4651](https://github.com/beego/beego/pull/4651) - [4651](https://github.com/beego/beego/pull/4651)
- [4644](https://github.com/beego/beego/pull/4644) - [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)

View File

@ -22,10 +22,8 @@ import (
"github.com/beego/beego/v2/server/web/context" "github.com/beego/beego/v2/server/web/context"
) )
var (
// BeeApp is an application instance // BeeApp is an application instance
BeeApp *App var BeeApp *App
)
func init() { func init() {
// create beego application // create beego application

View File

@ -36,10 +36,6 @@ type M web.M
// Hook function to run // Hook function to run
type hookfunc func() error type hookfunc func() error
var (
hooks = make([]hookfunc, 0) // hook function slice to store the hookfunc
)
// AddAPPStartHook is used to register the hookfunc // AddAPPStartHook is used to register the hookfunc
// The hookfuncs will run in beego.Run() // The hookfuncs will run in beego.Run()
// such as initiating session , starting middleware , building template, starting admin control and so on. // such as initiating session , starting middleware , building template, starting admin control and so on.

View File

@ -48,9 +48,11 @@ type ControllerCommentsSlice web.ControllerCommentsSlice
func (p ControllerCommentsSlice) Len() int { func (p ControllerCommentsSlice) Len() int {
return (web.ControllerCommentsSlice)(p).Len() return (web.ControllerCommentsSlice)(p).Len()
} }
func (p ControllerCommentsSlice) Less(i, j int) bool { func (p ControllerCommentsSlice) Less(i, j int) bool {
return (web.ControllerCommentsSlice)(p).Less(i, j) return (web.ControllerCommentsSlice)(p).Less(i, j)
} }
func (p ControllerCommentsSlice) Swap(i, j int) { func (p ControllerCommentsSlice) Swap(i, j int) {
(web.ControllerCommentsSlice)(p).Swap(i, j) (web.ControllerCommentsSlice)(p).Swap(i, j)
} }

View File

@ -18,7 +18,5 @@ import (
"github.com/beego/beego/v2/client/orm" "github.com/beego/beego/v2/client/orm"
) )
var (
// ErrMissPK missing pk error // ErrMissPK missing pk error
ErrMissPK = orm.ErrMissPK var ErrMissPK = orm.ErrMissPK
)

View File

@ -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)
}

View File

@ -72,5 +72,4 @@ func TestRedisSentinel(t *testing.T) {
assert.Nil(t, password) assert.Nil(t, password)
sess.SessionRelease(w) sess.SessionRelease(w)
} }

View File

@ -22,14 +22,14 @@ import (
"time" "time"
) )
const sid = "Session_id" const (
const sidNew = "Session_id_new" sid = "Session_id"
const sessionPath = "./_session_runtime" sidNew = "Session_id_new"
sessionPath = "./_session_runtime"
var (
mutex sync.Mutex
) )
var mutex sync.Mutex
func TestFileProviderSessionExist(t *testing.T) { func TestFileProviderSessionExist(t *testing.T) {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()

View File

@ -118,7 +118,6 @@ func AssetsJs(text string) template.HTML {
// AssetsCSS returns stylesheet link tag with src string. // AssetsCSS returns stylesheet link tag with src string.
func AssetsCSS(text string) template.HTML { func AssetsCSS(text string) template.HTML {
text = "<link href=\"" + text + "\" rel=\"stylesheet\" />" text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"
return template.HTML(text) return template.HTML(text)

View File

@ -79,7 +79,6 @@ func TestHtmlunquote(t *testing.T) {
h := `&lt;&#39;&nbsp;&rdquo;&ldquo;&amp;&#34;&gt;` h := `&lt;&#39;&nbsp;&rdquo;&ldquo;&amp;&#34;&gt;`
s := `<' ”“&">` s := `<' ”“&">`
assert.Equal(t, s, Htmlunquote(h)) assert.Equal(t, s, Htmlunquote(h))
} }
func TestParseForm(t *testing.T) { func TestParseForm(t *testing.T) {
@ -234,5 +233,4 @@ func TestMapGet(t *testing.T) {
res, err = MapGet(m5, 5, 4, 3, 2, 1) res, err = MapGet(m5, 5, 4, 3, 2, 1)
assert.Nil(t, err) assert.Nil(t, err)
assert.Nil(t, res) assert.Nil(t, res)
} }

View File

@ -14,12 +14,7 @@
package testing package testing
import ( import "github.com/beego/beego/v2/client/httplib/testing"
"github.com/beego/beego/v2/client/httplib/testing"
)
var port = ""
var baseURL = "http://localhost:"
// TestHTTPRequest beego test request client // TestHTTPRequest beego test request client
type TestHTTPRequest testing.TestHTTPRequest type TestHTTPRequest testing.TestHTTPRequest

View File

@ -16,19 +16,10 @@ package toolbox
import ( import (
"io" "io"
"os"
"time"
"github.com/beego/beego/v2/core/admin" "github.com/beego/beego/v2/core/admin"
) )
var startTime = time.Now()
var pid int
func init() {
pid = os.Getpid()
}
// ProcessInput parse input command string // ProcessInput parse input command string
func ProcessInput(input string, w io.Writer) { func ProcessInput(input string, w io.Writer) {
admin.ProcessInput(input, w) admin.ProcessInput(input, w)

View File

@ -80,7 +80,6 @@ type Task struct {
// NewTask add new task with name, time and func // NewTask add new task with name, time and func
func NewTask(tname string, spec string, f TaskFunc) *Task { func NewTask(tname string, spec string, f TaskFunc) *Task {
task := task.NewTask(tname, spec, func(ctx context.Context) error { task := task.NewTask(tname, spec, func(ctx context.Context) error {
return f() return f()
}) })
@ -98,7 +97,6 @@ func (t *Task) GetSpec() string {
// GetStatus get current task status // GetStatus get current task status
func (t *Task) GetStatus() string { func (t *Task) GetStatus() string {
t.initDelegate() t.initDelegate()
return t.delegate.GetStatus(context.Background()) return t.delegate.GetStatus(context.Background())
@ -222,7 +220,6 @@ type MapSorter task.MapSorter
// NewMapSorter create new tasker map // NewMapSorter create new tasker map
func NewMapSorter(m map[string]Tasker) *MapSorter { func NewMapSorter(m map[string]Tasker) *MapSorter {
newTaskerMap := make(map[string]task.Tasker, len(m)) newTaskerMap := make(map[string]task.Tasker, len(m))
for key, value := range 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())) return ms.Vals[i].GetNext(context.Background()).Before(ms.Vals[j].GetNext(context.Background()))
} }
func (ms *MapSorter) Swap(i, j int) { func (ms *MapSorter) Swap(i, j int) {
ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i] ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i]
ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i] ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i]

View File

@ -69,9 +69,7 @@ import (
beecontext "github.com/beego/beego/v2/server/web/context" beecontext "github.com/beego/beego/v2/server/web/context"
) )
var ( var defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
)
const ( const (
// default captcha attributes // default captcha attributes

View File

@ -28,8 +28,8 @@ func TestPrint(t *testing.T) {
} }
func TestPrintPoint(t *testing.T) { func TestPrintPoint(t *testing.T) {
var v1 = new(mytype) v1 := new(mytype)
var v2 = new(mytype) v2 := new(mytype)
v1.prev = nil v1.prev = nil
v1.next = v2 v1.next = v2

View File

@ -19,6 +19,7 @@ import (
) )
type reducetype func(interface{}) interface{} type reducetype func(interface{}) interface{}
type filtertype func(interface{}) bool type filtertype func(interface{}) bool
// InSlice checks given string in string slice or not. // InSlice checks given string in string slice or not.

View File

@ -27,9 +27,7 @@ const (
LabelTag = validation.LabelTag LabelTag = validation.LabelTag
) )
var ( var ErrInt64On32 = validation.ErrInt64On32
ErrInt64On32 = validation.ErrInt64On32
)
// CustomFunc is for custom validate function // CustomFunc is for custom validate function
type CustomFunc func(v *Validation, obj interface{}, key string) type CustomFunc func(v *Validation, obj interface{}, key string)

View File

@ -50,7 +50,6 @@ func TestMin(t *testing.T) {
assert.False(t, valid.Min(-1, 0, "min0").Ok) assert.False(t, valid.Min(-1, 0, "min0").Ok)
assert.True(t, valid.Min(1, 0, "min0").Ok) assert.True(t, valid.Min(1, 0, "min0").Ok)
} }
func TestMax(t *testing.T) { func TestMax(t *testing.T) {
@ -502,5 +501,4 @@ func TestCanSkipAlso(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.True(t, b) assert.True(t, b)
} }