Merge pull request #4615 from Loyalsoldier/format-code

Chore: format code
This commit is contained in:
Ming Deng 2021-05-19 22:57:20 +08:00 committed by GitHub
commit 3815d38ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 108 additions and 169 deletions

View File

@ -36,3 +36,9 @@ linters:
- whitespace
disable:
- errcheck
linters-settings:
gci:
local-prefixes: github.com/beego/beego
goimports:
local-prefixes: github.com/beego/beego

View File

@ -1,6 +1,7 @@
# developing
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
- Chore: format code. [4615](https://github.com/beego/beego/pull/4615)
- Chore: update dependencies. [4611](https://github.com/beego/beego/pull/4611)
- Update orm_test.go/TestInsertOrUpdate with table-driven. [4609](https://github.com/beego/beego/pull/4609)
- Add: Resp() method for web.Controller. [4588](https://github.com/beego/beego/pull/4588)

View File

@ -23,13 +23,7 @@ import (
"github.com/stretchr/testify/assert"
)
const (
initError = "init err"
setError = "set Error"
checkError = "check err"
getError = "get err"
getMultiError = "GetMulti Error"
)
const initError = "init err"
func TestCacheIncr(t *testing.T) {
bm, err := NewCache("memory", `{"interval":20}`)
@ -100,7 +94,6 @@ func TestCache(t *testing.T) {
assert.Equal(t, 2, len(vv))
assert.Equal(t, "author", vv[0])
assert.Equal(t, "author1", vv[1])

View File

@ -26,16 +26,7 @@ import (
"github.com/beego/beego/v2/adapter/cache"
)
const (
initError = "init err"
setError = "set Error"
checkError = "check err"
getError = "get err"
getMultiError = "GetMulti Error"
)
func TestMemcacheCache(t *testing.T) {
addr := os.Getenv("MEMCACHE_ADDR")
if addr == "" {
addr = "127.0.0.1:11211"

View File

@ -29,9 +29,6 @@ import (
const (
initError = "init err"
setError = "set Error"
checkError = "check err"
getError = "get err"
getMultiError = "GetMulti Error"
)
func TestRedisCache(t *testing.T) {
@ -121,5 +118,4 @@ func TestCacheScan(t *testing.T) {
if err = bm.ClearAll(); err != nil {
t.Error("clear all err")
}
}

View File

@ -12,14 +12,6 @@ import (
"github.com/beego/beego/v2/adapter/cache"
)
const (
initError = "init err"
setError = "set Error"
checkError = "check err"
getError = "get err"
getMultiError = "GetMulti Error"
)
func TestSsdbcacheCache(t *testing.T) {
ssdbAddr := os.Getenv("SSDB_ADDR")
if ssdbAddr == "" {

View File

@ -23,7 +23,6 @@ import (
"github.com/beego/beego/v2/adapter/context"
)
// Demo is used to test, it's empty
func Demo(i int) {

View File

@ -19,9 +19,8 @@ import (
"net/url"
"github.com/beego/beego/v2/adapter/session"
webContext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
webContext "github.com/beego/beego/v2/server/web/context"
)
var (

View File

@ -18,9 +18,8 @@ import (
"net/http"
"github.com/beego/beego/v2/adapter/context"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
beecontext "github.com/beego/beego/v2/server/web/context"
)
const (

View File

@ -18,21 +18,19 @@ import (
"strings"
"github.com/beego/beego/v2/core/logs"
webLog "github.com/beego/beego/v2/core/logs"
)
// Log levels to control the logging output.
// Deprecated: use github.com/beego/beego/v2/core/logs instead.
const (
LevelEmergency = webLog.LevelEmergency
LevelAlert = webLog.LevelAlert
LevelCritical = webLog.LevelCritical
LevelError = webLog.LevelError
LevelWarning = webLog.LevelWarning
LevelNotice = webLog.LevelNotice
LevelInformational = webLog.LevelInformational
LevelDebug = webLog.LevelDebug
LevelEmergency = logs.LevelEmergency
LevelAlert = logs.LevelAlert
LevelCritical = logs.LevelCritical
LevelError = logs.LevelError
LevelWarning = logs.LevelWarning
LevelNotice = logs.LevelNotice
LevelInformational = logs.LevelInformational
LevelDebug = logs.LevelDebug
)
// BeeLogger references the used application logger.

View File

@ -18,9 +18,8 @@ import (
"net/http"
adtContext "github.com/beego/beego/v2/adapter/context"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
)
type namespaceCond func(*adtContext.Context) bool

View File

@ -37,10 +37,9 @@ package cors
import (
beego "github.com/beego/beego/v2/adapter"
"github.com/beego/beego/v2/adapter/context"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/filter/cors"
"github.com/beego/beego/v2/adapter/context"
)
// Options represents Access Control options.

View File

@ -19,9 +19,8 @@ import (
"time"
beecontext "github.com/beego/beego/v2/adapter/context"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
)
// default filter execution points

View File

@ -37,7 +37,6 @@ import (
"net/http"
"github.com/beego/beego/v2/adapter/session"
beemem "github.com/beego/beego/v2/server/web/session/memcache"
)

View File

@ -44,11 +44,11 @@ import (
"context"
"net/http"
"github.com/beego/beego/v2/adapter/session"
"github.com/beego/beego/v2/server/web/session/mysql"
// import mysql driver
_ "github.com/go-sql-driver/mysql"
"github.com/beego/beego/v2/adapter/session"
"github.com/beego/beego/v2/server/web/session/mysql"
)
var (

View File

@ -54,10 +54,10 @@ import (
"context"
"net/http"
"github.com/beego/beego/v2/adapter/session"
// import postgresql Driver
_ "github.com/lib/pq"
"github.com/beego/beego/v2/adapter/session"
"github.com/beego/beego/v2/server/web/session/postgres"
)

View File

@ -37,7 +37,6 @@ import (
"net/http"
"github.com/beego/beego/v2/adapter/session"
beeRedis "github.com/beego/beego/v2/server/web/session/redis"
)

View File

@ -37,7 +37,6 @@ import (
"net/http"
"github.com/beego/beego/v2/adapter/session"
sentinel "github.com/beego/beego/v2/server/web/session/redis_sentinel"
)

View File

@ -5,7 +5,6 @@ import (
"net/http"
"github.com/beego/beego/v2/adapter/session"
beeSsdb "github.com/beego/beego/v2/server/web/session/ssdb"
)

View File

@ -198,7 +198,6 @@ func TestMapGet(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, int64(2), res)
res, err = MapGet(m1, 1)
assert.Nil(t, err)
assert.Equal(t, int64(2), res)

View File

@ -16,9 +16,8 @@ package adapter
import (
"github.com/beego/beego/v2/adapter/context"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
beecontext "github.com/beego/beego/v2/server/web/context"
)
// Tree has three elements: FixRouter/wildcard/leaves

View File

@ -63,11 +63,10 @@ import (
"net/http"
"time"
"github.com/beego/beego/v2/server/web/captcha"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/adapter/cache"
"github.com/beego/beego/v2/adapter/context"
"github.com/beego/beego/v2/server/web/captcha"
beecontext "github.com/beego/beego/v2/server/web/context"
)
var (

View File

@ -101,8 +101,6 @@ func TestCache(t *testing.T) {
assert.Equal(t, "author", vv[0])
assert.Equal(t, "author1", vv[1])
vv, err = bm.GetMulti(context.Background(), []string{"astaxie0", "astaxie1"})
assert.Equal(t, 2, len(vv))
assert.Nil(t, vv[0])
@ -179,7 +177,6 @@ func testIncrDecr(t *testing.T, c Cache, beforeIncr interface{}, afterIncr inter
assert.Nil(t, c.Put(ctx, key, beforeIncr, timeout))
assert.Nil(t, c.Incr(ctx, key))
v, _ := c.Get(ctx, key)
assert.Equal(t, afterIncr, v)

View File

@ -12,8 +12,6 @@ var (
ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64")
)
func incr(originVal interface{}) (interface{}, error) {
switch val := originVal.(type) {
case int:

View File

@ -123,14 +123,6 @@ var InvalidSsdbCacheValue = berror.DefineCode(4002022, moduleName, "InvalidSsdbC
SSDB cache only accept string value. Please check your input.
`)
var DeleteFileCacheItemFailed = berror.DefineCode(5002001, moduleName, "DeleteFileCacheItemFailed", `
Beego try to delete file cache item failed.
Please check whether Beego generated file correctly.

View File

@ -86,7 +86,6 @@ func TestMemcacheCache(t *testing.T) {
// test GetMulti
assert.Nil(t, bm.Put(context.Background(), "astaxie1", "author1", timeoutDuration))
res, _ = bm.IsExist(context.Background(), "astaxie1")
assert.True(t, res)

View File

@ -40,7 +40,6 @@ func TestRedisCache(t *testing.T) {
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
res, _ := bm.IsExist(context.Background(), "astaxie")
assert.True(t, res)
@ -51,7 +50,6 @@ func TestRedisCache(t *testing.T) {
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
val, _ := bm.Get(context.Background(), "astaxie")
v, _ := redis.Int(val, err)
assert.Equal(t, 1, v)

View File

@ -20,8 +20,9 @@ import (
"testing"
"time"
"github.com/beego/beego/v2/client/httplib"
"github.com/stretchr/testify/assert"
"github.com/beego/beego/v2/client/httplib"
)
func TestFilterChain(t *testing.T) {

View File

@ -56,6 +56,7 @@ import (
)
const contentTypeKey = "Content-Type"
// it will be the last filter and execute request.Do
var doRequestFilter = func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) {
return req.doRequest(ctx)

View File

@ -19,10 +19,9 @@ import (
"reflect"
"strings"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/bean"
"github.com/beego/beego/v2/core/logs"
)
// DefaultValueFilterChainBuilder only works for InsertXXX method,

View File

@ -21,9 +21,9 @@ import (
"sync"
"testing"
"github.com/beego/beego/v2/core/utils"
"github.com/stretchr/testify/assert"
"github.com/beego/beego/v2/core/utils"
)
func TestFilterOrmDecorator_Read(t *testing.T) {

View File

@ -25,8 +25,6 @@ import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
// As tidb can't use go get, so disable the tidb testing now
// _ "github.com/pingcap/tidb"
)
// A slice string field.

View File

@ -63,11 +63,9 @@ import (
"time"
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
"github.com/beego/beego/v2/client/orm/hints"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/utils"
)
// DebugQueries define the debug

View File

@ -31,11 +31,10 @@ import (
"testing"
"time"
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
"github.com/beego/beego/v2/client/orm/hints"
"github.com/stretchr/testify/assert"
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
"github.com/beego/beego/v2/client/orm/hints"
)
var _ = os.PathSeparator

View File

@ -138,7 +138,6 @@ type txEnder interface {
RollbackUnlessCommit() error
}
// Data Manipulation Language
type DML interface {
// insert model data to database
@ -241,7 +240,6 @@ type DriverGetter interface {
Driver() Driver
}
type ormer interface {
DQL
DML

View File

@ -39,12 +39,11 @@ import (
"strings"
"sync"
"github.com/beego/x2j"
"github.com/mitchellh/mapstructure"
"github.com/beego/beego/v2/core/config"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/x2j"
)
// Config is a xml config parser and implements Config interface.

View File

@ -267,7 +267,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
// set levelLoggerImpl to ensure all log message will be write out
err = bl.writeMsg(lm)
if err == nil {
return len(p), err
return len(p), nil
}
return 0, err
}

View File

@ -18,7 +18,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBeeLoggerDelLogger(t *testing.T) {

View File

@ -68,7 +68,6 @@ import (
"time"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"

View File

@ -27,10 +27,9 @@ import (
"github.com/beego/beego/v2"
"github.com/beego/beego/v2/core/config"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/session"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/session"
)
// Config is the main struct for BConfig

View File

@ -35,9 +35,8 @@ import (
"strings"
"time"
"github.com/beego/beego/v2/server/web/session"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web/session"
)
// Commonly used mime-types

View File

@ -32,11 +32,12 @@ import (
"strings"
"sync"
"github.com/gogo/protobuf/proto"
"gopkg.in/yaml.v2"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/context/param"
"github.com/beego/beego/v2/server/web/session"
"github.com/gogo/protobuf/proto"
"gopkg.in/yaml.v2"
)
var (
@ -436,6 +437,7 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
}
return URLFor(endpoint, values...)
}
// Resp sends response based on the Accept Header
// By default response will be in JSON
func (c *Controller) Resp(data interface{}) error {

View File

@ -24,9 +24,10 @@ import (
"strconv"
"testing"
"github.com/beego/beego/v2/server/web/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/beego/beego/v2/server/web/context"
)
func TestGetInt(t *testing.T) {

View File

@ -25,7 +25,6 @@ import (
"github.com/beego/beego/v2"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web/context"
)

View File

@ -152,7 +152,6 @@ func (l *limiter) createBucket(key string) bucket {
return b
}
func defaultSessionKey(r *http.Request) string {
return ""
}

View File

@ -5,10 +5,11 @@ import (
"net/http/httptest"
"testing"
"github.com/google/uuid"
"github.com/beego/beego/v2/server/web"
webContext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/session"
"github.com/google/uuid"
)
func testRequest(t *testing.T, handler *web.ControllerRegister, path string, method string, code int) {

View File

@ -2,12 +2,13 @@ package web
import (
"encoding/json"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/session"
"mime"
"net/http"
"path/filepath"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/session"
)
// register MIME type with content type

View File

@ -15,8 +15,9 @@
package mock
import (
beegoCtx "github.com/beego/beego/v2/server/web/context"
"net/http"
beegoCtx "github.com/beego/beego/v2/server/web/context"
)
func NewMockContext(req *http.Request) (*beegoCtx.Context, *HttpResponse) {

View File

@ -18,10 +18,12 @@ import (
"bytes"
"context"
"fmt"
"github.com/beego/beego/v2/server/web"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/beego/beego/v2/server/web"
)
type TestController struct {

View File

@ -16,10 +16,12 @@ package mock
import (
"context"
"net/http"
"github.com/google/uuid"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/session"
"github.com/google/uuid"
"net/http"
)
// NewSessionProvider create new SessionProvider
@ -66,7 +68,7 @@ func (s *SessionProvider) SessionRegenerate(ctx context.Context, oldsid, sid str
// SessionDestroy reset Store to nil
func (s *SessionProvider) SessionDestroy(ctx context.Context, sid string) error {
s.Store = nil;
s.Store = nil
return nil
}
@ -80,7 +82,6 @@ func (s *SessionProvider) SessionGC(ctx context.Context) {
// we do anything since we don't need to mock GC
}
type SessionStore struct {
sid string
values map[interface{}]interface{}
@ -120,6 +121,3 @@ func newSessionStore() *SessionStore {
values: make(map[interface{}]interface{}, 4),
}
}

View File

@ -16,10 +16,12 @@ package mock
import (
"bytes"
"github.com/beego/beego/v2/server/web"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/beego/beego/v2/server/web"
)
func TestSessionProvider(t *testing.T) {
@ -45,4 +47,3 @@ func TestSessionProvider(t *testing.T) {
assert.Equal(t, "Tom", result)
}

View File

@ -27,7 +27,6 @@ import (
"time"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/utils"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/context/param"

View File

@ -23,7 +23,6 @@ import (
"testing"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
)

View File

@ -32,9 +32,8 @@ import (
"golang.org/x/crypto/acme/autocert"
"github.com/beego/beego/v2/core/logs"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/core/utils"
beecontext "github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web/grace"
)

View File

@ -38,9 +38,9 @@ import (
"strings"
"sync"
"github.com/beego/beego/v2/server/web/session"
"github.com/bradfitz/gomemcache/memcache"
"github.com/beego/beego/v2/server/web/session"
)
var mempder = &MemProvider{}

View File

@ -47,9 +47,10 @@ import (
"sync"
"time"
"github.com/beego/beego/v2/server/web/session"
// import mysql driver
_ "github.com/go-sql-driver/mysql"
"github.com/beego/beego/v2/server/web/session"
)
var (

View File

@ -57,9 +57,10 @@ import (
"sync"
"time"
"github.com/beego/beego/v2/server/web/session"
// import postgresql Driver
_ "github.com/lib/pq"
"github.com/beego/beego/v2/server/web/session"
)
var postgresqlpder = &Provider{}

View File

@ -29,7 +29,6 @@ import (
lru "github.com/hashicorp/golang-lru"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
)

View File

@ -20,7 +20,6 @@ import (
"strings"
"github.com/beego/beego/v2/core/utils"
"github.com/beego/beego/v2/server/web/context"
)