Merge pull request #4615 from Loyalsoldier/format-code
Chore: format code
This commit is contained in:
commit
3815d38ef1
6
.github/linters/.golangci.yml
vendored
6
.github/linters/.golangci.yml
vendored
@ -36,3 +36,9 @@ linters:
|
|||||||
- whitespace
|
- whitespace
|
||||||
disable:
|
disable:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gci:
|
||||||
|
local-prefixes: github.com/beego/beego
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/beego/beego
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
# developing
|
# developing
|
||||||
|
|
||||||
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
|
- 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)
|
- 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)
|
- 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)
|
- 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
@ -23,13 +23,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const initError = "init err"
|
||||||
initError = "init err"
|
|
||||||
setError = "set Error"
|
|
||||||
checkError = "check err"
|
|
||||||
getError = "get err"
|
|
||||||
getMultiError = "GetMulti Error"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCacheIncr(t *testing.T) {
|
func TestCacheIncr(t *testing.T) {
|
||||||
bm, err := NewCache("memory", `{"interval":20}`)
|
bm, err := NewCache("memory", `{"interval":20}`)
|
||||||
@ -100,7 +94,6 @@ func TestCache(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, 2, len(vv))
|
assert.Equal(t, 2, len(vv))
|
||||||
|
|
||||||
|
|
||||||
assert.Equal(t, "author", vv[0])
|
assert.Equal(t, "author", vv[0])
|
||||||
|
|
||||||
assert.Equal(t, "author1", vv[1])
|
assert.Equal(t, "author1", vv[1])
|
||||||
|
|||||||
11
adapter/cache/memcache/memcache_test.go
vendored
11
adapter/cache/memcache/memcache_test.go
vendored
@ -26,16 +26,7 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/cache"
|
"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) {
|
func TestMemcacheCache(t *testing.T) {
|
||||||
|
|
||||||
addr := os.Getenv("MEMCACHE_ADDR")
|
addr := os.Getenv("MEMCACHE_ADDR")
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
addr = "127.0.0.1:11211"
|
addr = "127.0.0.1:11211"
|
||||||
@ -72,7 +63,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
assert.Nil(t, bm.Delete("astaxie"))
|
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))
|
assert.Nil(t, bm.Put("astaxie", "author", timeoutDuration))
|
||||||
|
|
||||||
|
|||||||
8
adapter/cache/redis/redis_test.go
vendored
8
adapter/cache/redis/redis_test.go
vendored
@ -28,10 +28,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
initError = "init err"
|
initError = "init err"
|
||||||
setError = "set Error"
|
setError = "set Error"
|
||||||
checkError = "check err"
|
|
||||||
getError = "get err"
|
|
||||||
getMultiError = "GetMulti Error"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRedisCache(t *testing.T) {
|
func TestRedisCache(t *testing.T) {
|
||||||
@ -52,7 +49,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
|
|
||||||
assert.False(t, bm.IsExist("astaxie"))
|
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)
|
v, err := redis.Int(bm.Get("astaxie"), err)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@ -121,5 +118,4 @@ func TestCacheScan(t *testing.T) {
|
|||||||
if err = bm.ClearAll(); err != nil {
|
if err = bm.ClearAll(); err != nil {
|
||||||
t.Error("clear all err")
|
t.Error("clear all err")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
adapter/cache/ssdb/ssdb_test.go
vendored
10
adapter/cache/ssdb/ssdb_test.go
vendored
@ -12,14 +12,6 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/cache"
|
"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) {
|
func TestSsdbcacheCache(t *testing.T) {
|
||||||
ssdbAddr := os.Getenv("SSDB_ADDR")
|
ssdbAddr := os.Getenv("SSDB_ADDR")
|
||||||
if ssdbAddr == "" {
|
if ssdbAddr == "" {
|
||||||
@ -70,7 +62,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
// test GetMulti done
|
// test GetMulti done
|
||||||
assert.Nil(t, ssdb.Put("ssdb1", "ssdb1", -10*time.Second))
|
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"})
|
vv := ssdb.GetMulti([]string{"ssdb", "ssdb1"})
|
||||||
assert.Equal(t, 2, len(vv))
|
assert.Equal(t, 2, len(vv))
|
||||||
|
|||||||
@ -185,7 +185,7 @@ func TestJson(t *testing.T) {
|
|||||||
|
|
||||||
m, ok := db.(map[string]interface{})
|
m, ok := db.(map[string]interface{})
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t,"host" , m["host"])
|
assert.Equal(t, "host", m["host"])
|
||||||
|
|
||||||
_, err = jsonconf.Int("unknown")
|
_, err = jsonconf.Int("unknown")
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|||||||
@ -23,9 +23,8 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/context"
|
"github.com/beego/beego/v2/adapter/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Demo is used to test, it's empty
|
// Demo is used to test, it's empty
|
||||||
func Demo(i int) {
|
func Demo(i int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,8 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
webContext "github.com/beego/beego/v2/server/web/context"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
|
webContext "github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -18,9 +18,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/context"
|
"github.com/beego/beego/v2/adapter/context"
|
||||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
|
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -18,21 +18,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
webLog "github.com/beego/beego/v2/core/logs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Log levels to control the logging output.
|
// Log levels to control the logging output.
|
||||||
// Deprecated: use github.com/beego/beego/v2/core/logs instead.
|
// Deprecated: use github.com/beego/beego/v2/core/logs instead.
|
||||||
const (
|
const (
|
||||||
LevelEmergency = webLog.LevelEmergency
|
LevelEmergency = logs.LevelEmergency
|
||||||
LevelAlert = webLog.LevelAlert
|
LevelAlert = logs.LevelAlert
|
||||||
LevelCritical = webLog.LevelCritical
|
LevelCritical = logs.LevelCritical
|
||||||
LevelError = webLog.LevelError
|
LevelError = logs.LevelError
|
||||||
LevelWarning = webLog.LevelWarning
|
LevelWarning = logs.LevelWarning
|
||||||
LevelNotice = webLog.LevelNotice
|
LevelNotice = logs.LevelNotice
|
||||||
LevelInformational = webLog.LevelInformational
|
LevelInformational = logs.LevelInformational
|
||||||
LevelDebug = webLog.LevelDebug
|
LevelDebug = logs.LevelDebug
|
||||||
)
|
)
|
||||||
|
|
||||||
// BeeLogger references the used application logger.
|
// BeeLogger references the used application logger.
|
||||||
|
|||||||
@ -18,9 +18,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
adtContext "github.com/beego/beego/v2/adapter/context"
|
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"
|
||||||
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type namespaceCond func(*adtContext.Context) bool
|
type namespaceCond func(*adtContext.Context) bool
|
||||||
|
|||||||
@ -37,10 +37,9 @@ package cors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
beego "github.com/beego/beego/v2/adapter"
|
beego "github.com/beego/beego/v2/adapter"
|
||||||
|
"github.com/beego/beego/v2/adapter/context"
|
||||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/beego/beego/v2/server/web/filter/cors"
|
"github.com/beego/beego/v2/server/web/filter/cors"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options represents Access Control options.
|
// Options represents Access Control options.
|
||||||
|
|||||||
@ -19,9 +19,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
beecontext "github.com/beego/beego/v2/adapter/context"
|
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"
|
||||||
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// default filter execution points
|
// default filter execution points
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
|
|
||||||
beemem "github.com/beego/beego/v2/server/web/session/memcache"
|
beemem "github.com/beego/beego/v2/server/web/session/memcache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -44,11 +44,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
|
||||||
"github.com/beego/beego/v2/server/web/session/mysql"
|
|
||||||
|
|
||||||
// import mysql driver
|
// import mysql driver
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
|
"github.com/beego/beego/v2/server/web/session/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -54,10 +54,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
|
||||||
// import postgresql Driver
|
// import postgresql Driver
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
"github.com/beego/beego/v2/server/web/session/postgres"
|
"github.com/beego/beego/v2/server/web/session/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
|
|
||||||
beeRedis "github.com/beego/beego/v2/server/web/session/redis"
|
beeRedis "github.com/beego/beego/v2/server/web/session/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
|
|
||||||
sentinel "github.com/beego/beego/v2/server/web/session/redis_sentinel"
|
sentinel "github.com/beego/beego/v2/server/web/session/redis_sentinel"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/session"
|
"github.com/beego/beego/v2/adapter/session"
|
||||||
|
|
||||||
beeSsdb "github.com/beego/beego/v2/server/web/session/ssdb"
|
beeSsdb "github.com/beego/beego/v2/server/web/session/ssdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -198,7 +198,6 @@ func TestMapGet(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, int64(2), res)
|
assert.Equal(t, int64(2), res)
|
||||||
|
|
||||||
|
|
||||||
res, err = MapGet(m1, 1)
|
res, err = MapGet(m1, 1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, int64(2), res)
|
assert.Equal(t, int64(2), res)
|
||||||
|
|||||||
@ -16,9 +16,8 @@ package adapter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/beego/v2/adapter/context"
|
"github.com/beego/beego/v2/adapter/context"
|
||||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
|
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tree has three elements: FixRouter/wildcard/leaves
|
// Tree has three elements: FixRouter/wildcard/leaves
|
||||||
|
|||||||
@ -63,11 +63,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"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/cache"
|
||||||
"github.com/beego/beego/v2/adapter/context"
|
"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 (
|
var (
|
||||||
|
|||||||
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"})
|
vv, _ := bm.GetMulti(context.Background(), []string{"astaxie", "astaxie1"})
|
||||||
assert.Equal(t, 2, len(vv))
|
assert.Equal(t, 2, len(vv))
|
||||||
assert.Equal(t, "author", vv[0])
|
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"})
|
vv, err = bm.GetMulti(context.Background(), []string{"astaxie0", "astaxie1"})
|
||||||
assert.Equal(t, 2, len(vv))
|
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"}`)
|
bm, err := NewCache("file", `{"CachePath":"cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}`)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
timeoutDuration := 10 * time.Second
|
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")
|
res, _ := bm.IsExist(context.Background(), "astaxie")
|
||||||
assert.True(t, res)
|
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.Put(ctx, key, beforeIncr, timeout))
|
||||||
assert.Nil(t, c.Incr(ctx, key))
|
assert.Nil(t, c.Incr(ctx, key))
|
||||||
|
|
||||||
|
|
||||||
v, _ := c.Get(ctx, key)
|
v, _ := c.Get(ctx, key)
|
||||||
assert.Equal(t, afterIncr, v)
|
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 (
|
var (
|
||||||
ErrIncrementOverflow = berror.Error(IncrementOverflow, "this incr invocation will overflow.")
|
ErrIncrementOverflow = berror.Error(IncrementOverflow, "this incr invocation will overflow.")
|
||||||
ErrDecrementOverflow = berror.Error(DecrementOverflow, "this decr 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) {
|
func incr(originVal interface{}) (interface{}, error) {
|
||||||
switch val := originVal.(type) {
|
switch val := originVal.(type) {
|
||||||
case int:
|
case int:
|
||||||
|
|||||||
8
client/cache/error_code.go
vendored
8
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.
|
SSDB cache only accept string value. Please check your input.
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var DeleteFileCacheItemFailed = berror.DefineCode(5002001, moduleName, "DeleteFileCacheItemFailed", `
|
var DeleteFileCacheItemFailed = berror.DefineCode(5002001, moduleName, "DeleteFileCacheItemFailed", `
|
||||||
Beego try to delete file cache item failed.
|
Beego try to delete file cache item failed.
|
||||||
Please check whether Beego generated file correctly.
|
Please check whether Beego generated file correctly.
|
||||||
|
|||||||
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
|
return "", err
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
err = os.MkdirAll(cachePath, os.ModePerm)
|
err = os.MkdirAll(cachePath, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", berror.Wrapf(err, CreateFileCacheDirFailed,
|
return "", berror.Wrapf(err, CreateFileCacheDirFailed,
|
||||||
"could not create the directory: %s", cachePath)
|
"could not create the directory: %s", cachePath)
|
||||||
@ -299,8 +299,8 @@ func FileGetContents(filename string) ([]byte, error) {
|
|||||||
data, err := ioutil.ReadFile(filename)
|
data, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, berror.Wrapf(err, ReadFileCacheContentFailed,
|
return nil, berror.Wrapf(err, ReadFileCacheContentFailed,
|
||||||
"could not read the data from the file: %s, " +
|
"could not read the data from the file: %s, "+
|
||||||
"please confirm that file exist and Beego has the permission to read the content.", filename)
|
"please confirm that file exist and Beego has the permission to read the content.", filename)
|
||||||
}
|
}
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|||||||
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)
|
mv, err := rc.conn.GetMulti(keys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rv, berror.Wrapf(err, cache.MemCacheCurdFailed,
|
return rv, berror.Wrapf(err, cache.MemCacheCurdFailed,
|
||||||
"could not read multiple key-values from memcache, " +
|
"could not read multiple key-values from memcache, "+
|
||||||
"please check your keys, network and connection. Root cause: %s",
|
"please check your keys, network and connection. Root cause: %s",
|
||||||
err.Error())
|
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")
|
res, _ = bm.IsExist(context.Background(), "astaxie")
|
||||||
assert.False(t, res)
|
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
|
// test string
|
||||||
res, _ = bm.IsExist(context.Background(), "astaxie")
|
res, _ = bm.IsExist(context.Background(), "astaxie")
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
@ -86,7 +86,6 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
// test GetMulti
|
// test GetMulti
|
||||||
assert.Nil(t, bm.Put(context.Background(), "astaxie1", "author1", timeoutDuration))
|
assert.Nil(t, bm.Put(context.Background(), "astaxie1", "author1", timeoutDuration))
|
||||||
|
|
||||||
|
|
||||||
res, _ = bm.IsExist(context.Background(), "astaxie1")
|
res, _ = bm.IsExist(context.Background(), "astaxie1")
|
||||||
assert.True(t, res)
|
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))
|
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
|
||||||
|
|
||||||
|
|
||||||
res, _ := bm.IsExist(context.Background(), "astaxie")
|
res, _ := bm.IsExist(context.Background(), "astaxie")
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
|
|
||||||
@ -51,7 +50,6 @@ func TestRedisCache(t *testing.T) {
|
|||||||
|
|
||||||
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
|
assert.Nil(t, bm.Put(context.Background(), "astaxie", 1, timeoutDuration))
|
||||||
|
|
||||||
|
|
||||||
val, _ := bm.Get(context.Background(), "astaxie")
|
val, _ := bm.Get(context.Background(), "astaxie")
|
||||||
v, _ := redis.Int(val, err)
|
v, _ := redis.Int(val, err)
|
||||||
assert.Equal(t, 1, v)
|
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 := 3 * time.Second
|
||||||
// timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
// 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")
|
res, _ = ssdb.IsExist(context.Background(), "ssdb")
|
||||||
assert.True(t, res)
|
assert.True(t, res)
|
||||||
@ -87,7 +87,7 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
assert.Equal(t, 2, len(vv))
|
assert.Equal(t, 2, len(vv))
|
||||||
|
|
||||||
assert.Equal(t, "ssdb", vv[0])
|
assert.Equal(t, "ssdb", vv[0])
|
||||||
assert.Nil(t, vv[1])
|
assert.Nil(t, vv[1])
|
||||||
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
assert.True(t, strings.Contains(err.Error(), "key not exist"))
|
assert.True(t, strings.Contains(err.Error(), "key not exist"))
|
||||||
|
|||||||
@ -20,8 +20,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/httplib"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/httplib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilterChain(t *testing.T) {
|
func TestFilterChain(t *testing.T) {
|
||||||
|
|||||||
@ -56,6 +56,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const contentTypeKey = "Content-Type"
|
const contentTypeKey = "Content-Type"
|
||||||
|
|
||||||
// it will be the last filter and execute request.Do
|
// it will be the last filter and execute request.Do
|
||||||
var doRequestFilter = func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) {
|
var doRequestFilter = func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) {
|
||||||
return req.doRequest(ctx)
|
return req.doRequest(ctx)
|
||||||
|
|||||||
@ -19,10 +19,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/bean"
|
"github.com/beego/beego/v2/core/bean"
|
||||||
|
"github.com/beego/beego/v2/core/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultValueFilterChainBuilder only works for InsertXXX method,
|
// DefaultValueFilterChainBuilder only works for InsertXXX method,
|
||||||
|
|||||||
@ -21,9 +21,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/core/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilterOrmDecorator_Read(t *testing.T) {
|
func TestFilterOrmDecorator_Read(t *testing.T) {
|
||||||
|
|||||||
@ -241,7 +241,7 @@ func TestTransactionRollback(t *testing.T) {
|
|||||||
assert.Equal(t, mock, err)
|
assert.Equal(t, mock, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTransactionRollbackUnlessCommit(t *testing.T) {
|
func TestTransactionRollbackUnlessCommit(t *testing.T) {
|
||||||
s := StartMock()
|
s := StartMock()
|
||||||
defer s.Clear()
|
defer s.Clear()
|
||||||
mock := errors.New(mockErrorMsg)
|
mock := errors.New(mockErrorMsg)
|
||||||
|
|||||||
@ -25,8 +25,6 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "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.
|
// A slice string field.
|
||||||
|
|||||||
@ -63,11 +63,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/client/orm/hints"
|
"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/logs"
|
||||||
|
"github.com/beego/beego/v2/core/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DebugQueries define the debug
|
// DebugQueries define the debug
|
||||||
|
|||||||
@ -31,11 +31,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||||
|
"github.com/beego/beego/v2/client/orm/hints"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = os.PathSeparator
|
var _ = os.PathSeparator
|
||||||
|
|||||||
@ -138,7 +138,6 @@ type txEnder interface {
|
|||||||
RollbackUnlessCommit() error
|
RollbackUnlessCommit() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Data Manipulation Language
|
// Data Manipulation Language
|
||||||
type DML interface {
|
type DML interface {
|
||||||
// insert model data to database
|
// insert model data to database
|
||||||
@ -241,7 +240,6 @@ type DriverGetter interface {
|
|||||||
Driver() Driver
|
Driver() Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type ormer interface {
|
type ormer interface {
|
||||||
DQL
|
DQL
|
||||||
DML
|
DML
|
||||||
|
|||||||
@ -39,12 +39,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/beego/x2j"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/config"
|
"github.com/beego/beego/v2/core/config"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
"github.com/beego/x2j"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is a xml config parser and implements Config interface.
|
// Config is a xml config parser and implements Config interface.
|
||||||
|
|||||||
@ -261,13 +261,13 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
|
|||||||
lm := &LogMsg{
|
lm := &LogMsg{
|
||||||
Msg: string(p),
|
Msg: string(p),
|
||||||
Level: levelLoggerImpl,
|
Level: levelLoggerImpl,
|
||||||
When: time.Now(),
|
When: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// set levelLoggerImpl to ensure all log message will be write out
|
// set levelLoggerImpl to ensure all log message will be write out
|
||||||
err = bl.writeMsg(lm)
|
err = bl.writeMsg(lm)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return len(p), err
|
return len(p), nil
|
||||||
}
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBeeLoggerDelLogger(t *testing.T) {
|
func TestBeeLoggerDelLogger(t *testing.T) {
|
||||||
|
|||||||
@ -68,7 +68,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
|
|||||||
@ -27,10 +27,9 @@ import (
|
|||||||
"github.com/beego/beego/v2"
|
"github.com/beego/beego/v2"
|
||||||
"github.com/beego/beego/v2/core/config"
|
"github.com/beego/beego/v2/core/config"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"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/core/utils"
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the main struct for BConfig
|
// Config is the main struct for BConfig
|
||||||
|
|||||||
@ -35,9 +35,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Commonly used mime-types
|
// Commonly used mime-types
|
||||||
|
|||||||
@ -32,11 +32,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"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"
|
||||||
"github.com/beego/beego/v2/server/web/context/param"
|
"github.com/beego/beego/v2/server/web/context/param"
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -436,6 +437,7 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
|
|||||||
}
|
}
|
||||||
return URLFor(endpoint, values...)
|
return URLFor(endpoint, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resp sends response based on the Accept Header
|
// Resp sends response based on the Accept Header
|
||||||
// By default response will be in JSON
|
// By default response will be in JSON
|
||||||
func (c *Controller) Resp(data interface{}) error {
|
func (c *Controller) Resp(data interface{}) error {
|
||||||
|
|||||||
@ -24,9 +24,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetInt(t *testing.T) {
|
func TestGetInt(t *testing.T) {
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
"github.com/beego/beego/v2"
|
"github.com/beego/beego/v2"
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -152,7 +152,6 @@ func (l *limiter) createBucket(key string) bucket {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func defaultSessionKey(r *http.Request) string {
|
func defaultSessionKey(r *http.Request) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,11 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
webContext "github.com/beego/beego/v2/server/web/context"
|
webContext "github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
"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) {
|
func testRequest(t *testing.T, handler *web.ControllerRegister, path string, method string, code int) {
|
||||||
|
|||||||
@ -2,12 +2,13 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"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
|
// register MIME type with content type
|
||||||
|
|||||||
@ -15,8 +15,9 @@
|
|||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
beegoCtx "github.com/beego/beego/v2/server/web/context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
beegoCtx "github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewMockContext(req *http.Request) (*beegoCtx.Context, *HttpResponse) {
|
func NewMockContext(req *http.Request) (*beegoCtx.Context, *HttpResponse) {
|
||||||
|
|||||||
@ -18,10 +18,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/beego/v2/server/web"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestController struct {
|
type TestController struct {
|
||||||
@ -58,7 +60,7 @@ func (c *TestController) HelloSession() {
|
|||||||
c.Ctx.WriteString("set")
|
c.Ctx.WriteString("set")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestController) HelloSessionName() {
|
func (c *TestController) HelloSessionName() {
|
||||||
name := c.CruSession.Get(context.Background(), "name")
|
name := c.CruSession.Get(context.Background(), "name")
|
||||||
c.Ctx.WriteString(name.(string))
|
c.Ctx.WriteString(name.(string))
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ type HttpResponse struct {
|
|||||||
// NewMockHttpResponse you should only use this in your test code
|
// NewMockHttpResponse you should only use this in your test code
|
||||||
func NewMockHttpResponse() *HttpResponse {
|
func NewMockHttpResponse() *HttpResponse {
|
||||||
return &HttpResponse{
|
return &HttpResponse{
|
||||||
body: make([]byte, 0),
|
body: make([]byte, 0),
|
||||||
header: make(http.Header),
|
header: make(http.Header),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,10 +16,12 @@ package mock
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
"github.com/google/uuid"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSessionProvider create new SessionProvider
|
// NewSessionProvider create new SessionProvider
|
||||||
@ -66,7 +68,7 @@ func (s *SessionProvider) SessionRegenerate(ctx context.Context, oldsid, sid str
|
|||||||
|
|
||||||
// SessionDestroy reset Store to nil
|
// SessionDestroy reset Store to nil
|
||||||
func (s *SessionProvider) SessionDestroy(ctx context.Context, sid string) error {
|
func (s *SessionProvider) SessionDestroy(ctx context.Context, sid string) error {
|
||||||
s.Store = nil;
|
s.Store = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,14 +82,13 @@ func (s *SessionProvider) SessionGC(ctx context.Context) {
|
|||||||
// we do anything since we don't need to mock GC
|
// we do anything since we don't need to mock GC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type SessionStore struct {
|
type SessionStore struct {
|
||||||
sid string
|
sid string
|
||||||
values map[interface{}]interface{}
|
values map[interface{}]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SessionStore) Set(ctx context.Context, key, value interface{}) error {
|
func (s *SessionStore) Set(ctx context.Context, key, value interface{}) error {
|
||||||
s.values[key]=value
|
s.values[key] = value
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,10 +117,7 @@ func (s *SessionStore) Flush(ctx context.Context) error {
|
|||||||
|
|
||||||
func newSessionStore() *SessionStore {
|
func newSessionStore() *SessionStore {
|
||||||
return &SessionStore{
|
return &SessionStore{
|
||||||
sid: uuid.New().String(),
|
sid: uuid.New().String(),
|
||||||
values: make(map[interface{}]interface{}, 4),
|
values: make(map[interface{}]interface{}, 4),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,12 @@ package mock
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/beego/beego/v2/server/web"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSessionProvider(t *testing.T) {
|
func TestSessionProvider(t *testing.T) {
|
||||||
@ -45,4 +47,3 @@ func TestSessionProvider(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, "Tom", result)
|
assert.Equal(t, "Tom", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/beego/beego/v2/server/web/context/param"
|
"github.com/beego/beego/v2/server/web/context/param"
|
||||||
@ -738,7 +737,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), "*")
|
pattern := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName), "*")
|
||||||
patternInit := path.Join(prefix, controllerName, methodName, "*")
|
patternInit := path.Join(prefix, controllerName, methodName, "*")
|
||||||
patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName))
|
patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName))
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -32,9 +32,8 @@ import (
|
|||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
|
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/beego/beego/v2/server/web/grace"
|
"github.com/beego/beego/v2/server/web/grace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -38,9 +38,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
|
||||||
|
|
||||||
"github.com/bradfitz/gomemcache/memcache"
|
"github.com/bradfitz/gomemcache/memcache"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mempder = &MemProvider{}
|
var mempder = &MemProvider{}
|
||||||
|
|||||||
@ -47,9 +47,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
|
||||||
// import mysql driver
|
// import mysql driver
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -57,9 +57,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
|
||||||
// import postgresql Driver
|
// import postgresql Driver
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
var postgresqlpder = &Provider{}
|
var postgresqlpder = &Provider{}
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import (
|
|||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/utils"
|
"github.com/beego/beego/v2/core/utils"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user