Merge branch 'develop' into develop

This commit is contained in:
jimashi
2021-05-20 18:27:41 +08:00
committed by GitHub
82 changed files with 796 additions and 503 deletions

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
@@ -94,4 +95,4 @@ func registerGzip() error {
)
}
return nil
}
}

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) {
@@ -24,4 +25,4 @@ func NewMockContext(req *http.Request) (*beegoCtx.Context, *HttpResponse) {
resp := NewMockHttpResponse()
ctx.Reset(resp, req)
return ctx, resp
}
}

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 {
@@ -58,7 +60,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))
}
}

View File

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

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,14 +82,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 +117,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),
}
}

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"
@@ -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), "*")
patternInit := path.Join(prefix, controllerName, methodName, "*")
patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(methodName))

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

@@ -31,7 +31,7 @@ var (
mutex sync.Mutex
)
func TestFileProvider_SessionInit(t *testing.T) {
func TestFileProviderSessionInit(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -48,7 +48,7 @@ func TestFileProvider_SessionInit(t *testing.T) {
}
}
func TestFileProvider_SessionExist(t *testing.T) {
func TestFileProviderSessionExist(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -79,7 +79,7 @@ func TestFileProvider_SessionExist(t *testing.T) {
}
}
func TestFileProvider_SessionExist2(t *testing.T) {
func TestFileProviderSessionExist2(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -113,7 +113,7 @@ func TestFileProvider_SessionExist2(t *testing.T) {
}
}
func TestFileProvider_SessionRead(t *testing.T) {
func TestFileProviderSessionRead(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -135,7 +135,7 @@ func TestFileProvider_SessionRead(t *testing.T) {
}
}
func TestFileProvider_SessionRead1(t *testing.T) {
func TestFileProviderSessionRead1(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -155,7 +155,7 @@ func TestFileProvider_SessionRead1(t *testing.T) {
}
}
func TestFileProvider_SessionAll(t *testing.T) {
func TestFileProviderSessionAll(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -178,7 +178,7 @@ func TestFileProvider_SessionAll(t *testing.T) {
}
}
func TestFileProvider_SessionRegenerate(t *testing.T) {
func TestFileProviderSessionRegenerate(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -222,7 +222,7 @@ func TestFileProvider_SessionRegenerate(t *testing.T) {
}
}
func TestFileProvider_SessionDestroy(t *testing.T) {
func TestFileProviderSessionDestroy(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -258,7 +258,7 @@ func TestFileProvider_SessionDestroy(t *testing.T) {
}
}
func TestFileProvider_SessionGC(t *testing.T) {
func TestFileProviderSessionGC(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -284,7 +284,7 @@ func TestFileProvider_SessionGC(t *testing.T) {
}
}
func TestFileSessionStore_Set(t *testing.T) {
func TestFileSessionStoreSet(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -303,7 +303,7 @@ func TestFileSessionStore_Set(t *testing.T) {
}
}
func TestFileSessionStore_Get(t *testing.T) {
func TestFileSessionStoreGet(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -324,7 +324,7 @@ func TestFileSessionStore_Get(t *testing.T) {
}
}
func TestFileSessionStore_Delete(t *testing.T) {
func TestFileSessionStoreDelete(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -347,7 +347,7 @@ func TestFileSessionStore_Delete(t *testing.T) {
}
}
func TestFileSessionStore_Flush(t *testing.T) {
func TestFileSessionStoreFlush(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -371,7 +371,7 @@ func TestFileSessionStore_Flush(t *testing.T) {
}
}
func TestFileSessionStore_SessionID(t *testing.T) {
func TestFileSessionStoreSessionID(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)
@@ -393,7 +393,7 @@ func TestFileSessionStore_SessionID(t *testing.T) {
}
}
func TestFileSessionStore_SessionRelease(t *testing.T) {
func TestFileSessionStoreSessionRelease(t *testing.T) {
mutex.Lock()
defer mutex.Unlock()
os.RemoveAll(sessionPath)

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"
)