Chore: format code
This commit is contained in:
parent
8f9eccefe9
commit
2b7401109f
@ -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)
|
||||
|
||||
9
adapter/cache/cache_test.go
vendored
9
adapter/cache/cache_test.go
vendored
@ -24,10 +24,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
getMultiError = "GetMulti Error"
|
||||
)
|
||||
|
||||
@ -100,7 +100,6 @@ func TestCache(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 2, len(vv))
|
||||
|
||||
|
||||
assert.Equal(t, "author", vv[0])
|
||||
|
||||
assert.Equal(t, "author1", vv[1])
|
||||
|
||||
10
adapter/cache/memcache/memcache_test.go
vendored
10
adapter/cache/memcache/memcache_test.go
vendored
@ -27,10 +27,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
getMultiError = "GetMulti Error"
|
||||
)
|
||||
|
||||
@ -72,7 +72,7 @@ func TestMemcacheCache(t *testing.T) {
|
||||
|
||||
assert.Nil(t, bm.Delete("astaxie"))
|
||||
|
||||
assert.False(t, bm.IsExist("astaxie"))
|
||||
assert.False(t, bm.IsExist("astaxie"))
|
||||
|
||||
assert.Nil(t, bm.Put("astaxie", "author", timeoutDuration))
|
||||
|
||||
|
||||
10
adapter/cache/redis/redis_test.go
vendored
10
adapter/cache/redis/redis_test.go
vendored
@ -27,10 +27,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
getMultiError = "GetMulti Error"
|
||||
)
|
||||
|
||||
@ -52,7 +52,7 @@ func TestRedisCache(t *testing.T) {
|
||||
|
||||
assert.False(t, bm.IsExist("astaxie"))
|
||||
|
||||
assert.Nil(t, bm.Put("astaxie", 1, timeoutDuration))
|
||||
assert.Nil(t, bm.Put("astaxie", 1, timeoutDuration))
|
||||
|
||||
v, err := redis.Int(bm.Get("astaxie"), err)
|
||||
assert.Nil(t, err)
|
||||
|
||||
10
adapter/cache/ssdb/ssdb_test.go
vendored
10
adapter/cache/ssdb/ssdb_test.go
vendored
@ -13,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
initError = "init err"
|
||||
setError = "set Error"
|
||||
checkError = "check err"
|
||||
getError = "get err"
|
||||
getMultiError = "GetMulti Error"
|
||||
)
|
||||
|
||||
@ -70,7 +70,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
||||
|
||||
// test GetMulti done
|
||||
assert.Nil(t, ssdb.Put("ssdb1", "ssdb1", -10*time.Second))
|
||||
assert.True(t, ssdb.IsExist("ssdb1") )
|
||||
assert.True(t, ssdb.IsExist("ssdb1"))
|
||||
|
||||
vv := ssdb.GetMulti([]string{"ssdb", "ssdb1"})
|
||||
assert.Equal(t, 2, len(vv))
|
||||
|
||||
@ -185,7 +185,7 @@ func TestJson(t *testing.T) {
|
||||
|
||||
m, ok := db.(map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t,"host" , m["host"])
|
||||
assert.Equal(t, "host", m["host"])
|
||||
|
||||
_, err = jsonconf.Int("unknown")
|
||||
assert.NotNil(t, err)
|
||||
|
||||
@ -23,9 +23,8 @@ import (
|
||||
"github.com/beego/beego/v2/adapter/context"
|
||||
)
|
||||
|
||||
|
||||
// Demo is used to test, it's empty
|
||||
func Demo(i int) {
|
||||
func Demo(i int) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ func TestCookie(t *testing.T) {
|
||||
t.Fatal("get username error")
|
||||
}
|
||||
sess.SessionRelease(w)
|
||||
|
||||
|
||||
if cookiestr := w.Header().Get(setCookieKey); cookiestr == "" {
|
||||
t.Fatal("setcookie error")
|
||||
} else {
|
||||
|
||||
@ -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)
|
||||
|
||||
7
client/cache/cache_test.go
vendored
7
client/cache/cache_test.go
vendored
@ -99,9 +99,7 @@ func TestCache(t *testing.T) {
|
||||
vv, _ := bm.GetMulti(context.Background(), []string{"astaxie", "astaxie1"})
|
||||
assert.Equal(t, 2, len(vv))
|
||||
assert.Equal(t, "author", vv[0])
|
||||
assert.Equal(t,"author1", vv[1])
|
||||
|
||||
|
||||
assert.Equal(t, "author1", vv[1])
|
||||
|
||||
vv, err = bm.GetMulti(context.Background(), []string{"astaxie0", "astaxie1"})
|
||||
assert.Equal(t, 2, len(vv))
|
||||
@ -116,7 +114,7 @@ func TestFileCache(t *testing.T) {
|
||||
bm, err := NewCache("file", `{"CachePath":"cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}`)
|
||||
assert.Nil(t, err)
|
||||
timeoutDuration := 10 * time.Second
|
||||
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
|
||||
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
|
||||
|
||||
res, _ := bm.IsExist(context.Background(), "astaxie")
|
||||
assert.True(t, res)
|
||||
@ -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)
|
||||
|
||||
|
||||
4
client/cache/calc_utils.go
vendored
4
client/cache/calc_utils.go
vendored
@ -9,11 +9,9 @@ import (
|
||||
var (
|
||||
ErrIncrementOverflow = berror.Error(IncrementOverflow, "this incr invocation will overflow.")
|
||||
ErrDecrementOverflow = berror.Error(DecrementOverflow, "this decr invocation will overflow.")
|
||||
ErrNotIntegerType = berror.Error(NotIntegerType, "item val is not (u)int (u)int32 (u)int64")
|
||||
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:
|
||||
|
||||
10
client/cache/error_code.go
vendored
10
client/cache/error_code.go
vendored
@ -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.
|
||||
@ -179,4 +171,4 @@ Usually it indicates something wrong on server side.
|
||||
`)
|
||||
|
||||
var ErrKeyExpired = berror.Error(KeyExpired, "the key is expired")
|
||||
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
||||
var ErrKeyNotExist = berror.Error(KeyNotExist, "the key isn't exist")
|
||||
|
||||
6
client/cache/file.go
vendored
6
client/cache/file.go
vendored
@ -140,7 +140,7 @@ func (fc *FileCache) getCacheFileName(key string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
if !ok {
|
||||
err = os.MkdirAll(cachePath, os.ModePerm)
|
||||
err = os.MkdirAll(cachePath, os.ModePerm)
|
||||
if err != nil {
|
||||
return "", berror.Wrapf(err, CreateFileCacheDirFailed,
|
||||
"could not create the directory: %s", cachePath)
|
||||
@ -299,8 +299,8 @@ func FileGetContents(filename string) ([]byte, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, berror.Wrapf(err, ReadFileCacheContentFailed,
|
||||
"could not read the data from the file: %s, " +
|
||||
"please confirm that file exist and Beego has the permission to read the content.", filename)
|
||||
"could not read the data from the file: %s, "+
|
||||
"please confirm that file exist and Beego has the permission to read the content.", filename)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
2
client/cache/file_test.go
vendored
2
client/cache/file_test.go
vendored
@ -105,4 +105,4 @@ func TestFileCacheDelete(t *testing.T) {
|
||||
|
||||
func getTestCacheFilePath() string {
|
||||
return filepath.Join(os.TempDir(), "test", "file.txt")
|
||||
}
|
||||
}
|
||||
|
||||
4
client/cache/memcache/memcache.go
vendored
4
client/cache/memcache/memcache.go
vendored
@ -71,8 +71,8 @@ func (rc *Cache) GetMulti(ctx context.Context, keys []string) ([]interface{}, er
|
||||
mv, err := rc.conn.GetMulti(keys)
|
||||
if err != nil {
|
||||
return rv, berror.Wrapf(err, cache.MemCacheCurdFailed,
|
||||
"could not read multiple key-values from memcache, " +
|
||||
"please check your keys, network and connection. Root cause: %s",
|
||||
"could not read multiple key-values from memcache, "+
|
||||
"please check your keys, network and connection. Root cause: %s",
|
||||
err.Error())
|
||||
}
|
||||
|
||||
|
||||
3
client/cache/memcache/memcache_test.go
vendored
3
client/cache/memcache/memcache_test.go
vendored
@ -74,7 +74,7 @@ func TestMemcacheCache(t *testing.T) {
|
||||
res, _ = bm.IsExist(context.Background(), "astaxie")
|
||||
assert.False(t, res)
|
||||
|
||||
assert.Nil(t,bm.Put(context.Background(), "astaxie", "author", timeoutDuration) )
|
||||
assert.Nil(t, bm.Put(context.Background(), "astaxie", "author", timeoutDuration))
|
||||
// test string
|
||||
res, _ = bm.IsExist(context.Background(), "astaxie")
|
||||
assert.True(t, res)
|
||||
@ -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)
|
||||
|
||||
|
||||
2
client/cache/redis/redis_test.go
vendored
2
client/cache/redis/redis_test.go
vendored
@ -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)
|
||||
|
||||
4
client/cache/ssdb/ssdb_test.go
vendored
4
client/cache/ssdb/ssdb_test.go
vendored
@ -30,7 +30,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
||||
timeoutDuration := 3 * time.Second
|
||||
// timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
||||
|
||||
assert.Nil(t, ssdb.Put(context.Background(), "ssdb", "ssdb", timeoutDuration))
|
||||
assert.Nil(t, ssdb.Put(context.Background(), "ssdb", "ssdb", timeoutDuration))
|
||||
|
||||
res, _ = ssdb.IsExist(context.Background(), "ssdb")
|
||||
assert.True(t, res)
|
||||
@ -87,7 +87,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
||||
assert.Equal(t, 2, len(vv))
|
||||
|
||||
assert.Equal(t, "ssdb", vv[0])
|
||||
assert.Nil(t, vv[1])
|
||||
assert.Nil(t, vv[1])
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "key not exist"))
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -164,4 +164,4 @@ func MockRollback(err error) *Mock {
|
||||
// MockRollbackUnlessCommit support RollbackUnlessCommit
|
||||
func MockRollbackUnlessCommit(err error) *Mock {
|
||||
return NewMock(NewSimpleCondition("", "RollbackUnlessCommit"), []interface{}{err}, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ func TestTransactionRollback(t *testing.T) {
|
||||
assert.Equal(t, mock, err)
|
||||
}
|
||||
|
||||
func TestTransactionRollbackUnlessCommit(t *testing.T) {
|
||||
func TestTransactionRollbackUnlessCommit(t *testing.T) {
|
||||
s := StartMock()
|
||||
defer s.Clear()
|
||||
mock := errors.New(mockErrorMsg)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -261,7 +261,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
|
||||
lm := &LogMsg{
|
||||
Msg: string(p),
|
||||
Level: levelLoggerImpl,
|
||||
When: time.Now(),
|
||||
When: time.Now(),
|
||||
}
|
||||
|
||||
// set levelLoggerImpl to ensure all log message will be write out
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
)
|
||||
|
||||
func TestBeeLoggerDelLogger(t *testing.T) {
|
||||
|
||||
@ -436,6 +436,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 {
|
||||
|
||||
@ -152,7 +152,6 @@ func (l *limiter) createBucket(key string) bucket {
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
func defaultSessionKey(r *http.Request) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -94,4 +94,4 @@ func registerGzip() error {
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,4 +24,4 @@ func NewMockContext(req *http.Request) (*beegoCtx.Context, *HttpResponse) {
|
||||
resp := NewMockHttpResponse()
|
||||
ctx.Reset(resp, req)
|
||||
return ctx, resp
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ func (c *TestController) HelloSession() {
|
||||
c.Ctx.WriteString("set")
|
||||
}
|
||||
|
||||
func (c *TestController) HelloSessionName() {
|
||||
func (c *TestController) HelloSessionName() {
|
||||
name := c.CruSession.Get(context.Background(), "name")
|
||||
c.Ctx.WriteString(name.(string))
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ type HttpResponse struct {
|
||||
// NewMockHttpResponse you should only use this in your test code
|
||||
func NewMockHttpResponse() *HttpResponse {
|
||||
return &HttpResponse{
|
||||
body: make([]byte, 0),
|
||||
body: make([]byte, 0),
|
||||
header: make(http.Header),
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,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,14 +80,13 @@ func (s *SessionProvider) SessionGC(ctx context.Context) {
|
||||
// we do anything since we don't need to mock GC
|
||||
}
|
||||
|
||||
|
||||
type SessionStore struct {
|
||||
sid string
|
||||
sid string
|
||||
values map[interface{}]interface{}
|
||||
}
|
||||
|
||||
func (s *SessionStore) Set(ctx context.Context, key, value interface{}) error {
|
||||
s.values[key]=value
|
||||
s.values[key] = value
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -116,10 +115,7 @@ func (s *SessionStore) Flush(ctx context.Context) error {
|
||||
|
||||
func newSessionStore() *SessionStore {
|
||||
return &SessionStore{
|
||||
sid: uuid.New().String(),
|
||||
sid: uuid.New().String(),
|
||||
values: make(map[interface{}]interface{}, 4),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -45,4 +45,3 @@ func TestSessionProvider(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "Tom", result)
|
||||
}
|
||||
|
||||
|
||||
@ -738,7 +738,7 @@ func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ControllerRegister) addAutoPrefixMethod(prefix, controllerName, methodName string, ctrl reflect.Type) {
|
||||
func (p *ControllerRegister) addAutoPrefixMethod(prefix, controllerName, methodName string, ctrl reflect.Type) {
|
||||
pattern := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName), "*")
|
||||
patternInit := path.Join(prefix, controllerName, methodName, "*")
|
||||
patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user