- {{.Content}}
- Go Home
-
- Powered by beego {{.BeegoVersion}}
-
-
-
-
-
-`
-
-// ErrorMaps holds map of http handlers for each error string.
-// there is 10 kinds default error(40x and 50x)
-var ErrorMaps = web.ErrorMaps
-
-// ErrorHandler registers http.HandlerFunc to each http err code string.
-// usage:
-// beego.ErrorHandler("404",NotFound)
-// beego.ErrorHandler("500",InternalServerError)
-func ErrorHandler(code string, h http.HandlerFunc) *App {
- return (*App)(web.ErrorHandler(code, h))
-}
-
-// ErrorController registers ControllerInterface to each http err code string.
-// usage:
-// beego.ErrorController(&controllers.ErrorController{})
-func ErrorController(c ControllerInterface) *App {
- return (*App)(web.ErrorController(c))
-}
-
-// Exception Write HttpStatus with errCode and Exec error handler if exist.
-func Exception(errCode uint64, ctx *context.Context) {
- web.Exception(errCode, (*beecontext.Context)(ctx))
-}
diff --git a/adapter/filter.go b/adapter/filter.go
deleted file mode 100644
index 660193b9..00000000
--- a/adapter/filter.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/server/web"
- beecontext "github.com/beego/beego/v2/server/web/context"
-)
-
-// FilterFunc defines a filter function which is invoked before the controller handler is executed.
-type FilterFunc func(*context.Context)
-
-// FilterRouter defines a filter operation which is invoked before the controller handler is executed.
-// It can match the URL against a pattern, and execute a filter function
-// when a request with a matching URL arrives.
-type FilterRouter web.FilterRouter
-
-// ValidRouter checks if the current request is matched by this filter.
-// If the request is matched, the values of the URL parameters defined
-// by the filter pattern are also returned.
-func (f *FilterRouter) ValidRouter(url string, ctx *context.Context) bool {
- return (*web.FilterRouter)(f).ValidRouter(url, (*beecontext.Context)(ctx))
-}
diff --git a/adapter/flash.go b/adapter/flash.go
deleted file mode 100644
index aab9b3ce..00000000
--- a/adapter/flash.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "github.com/beego/beego/v2/server/web"
-)
-
-// FlashData is a tools to maintain data when using across request.
-type FlashData web.FlashData
-
-// NewFlash return a new empty FlashData struct.
-func NewFlash() *FlashData {
- return (*FlashData)(web.NewFlash())
-}
-
-// Set message to flash
-func (fd *FlashData) Set(key string, msg string, args ...interface{}) {
- (*web.FlashData)(fd).Set(key, msg, args...)
-}
-
-// Success writes success message to flash.
-func (fd *FlashData) Success(msg string, args ...interface{}) {
- (*web.FlashData)(fd).Success(msg, args...)
-}
-
-// Notice writes notice message to flash.
-func (fd *FlashData) Notice(msg string, args ...interface{}) {
- (*web.FlashData)(fd).Notice(msg, args...)
-}
-
-// Warning writes warning message to flash.
-func (fd *FlashData) Warning(msg string, args ...interface{}) {
- (*web.FlashData)(fd).Warning(msg, args...)
-}
-
-// Error writes error message to flash.
-func (fd *FlashData) Error(msg string, args ...interface{}) {
- (*web.FlashData)(fd).Error(msg, args...)
-}
-
-// Store does the saving operation of flash data.
-// the data are encoded and saved in cookie.
-func (fd *FlashData) Store(c *Controller) {
- (*web.FlashData)(fd).Store((*web.Controller)(c))
-}
-
-// ReadFromRequest parsed flash data from encoded values in cookie.
-func ReadFromRequest(c *Controller) *FlashData {
- return (*FlashData)(web.ReadFromRequest((*web.Controller)(c)))
-}
diff --git a/adapter/fs.go b/adapter/fs.go
deleted file mode 100644
index 168e312a..00000000
--- a/adapter/fs.go
+++ /dev/null
@@ -1,35 +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 adapter
-
-import (
- "net/http"
- "path/filepath"
-
- "github.com/beego/beego/v2/server/web"
-)
-
-type FileSystem web.FileSystem
-
-func (d FileSystem) Open(name string) (http.File, error) {
- return (web.FileSystem)(d).Open(name)
-}
-
-// Walk walks the file tree rooted at root in filesystem, calling walkFn for each file or
-// directory in the tree, including root. All errors that arise visiting files
-// and directories are filtered by walkFn.
-func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
- return web.Walk(fs, root, walkFn)
-}
diff --git a/adapter/grace/grace.go b/adapter/grace/grace.go
deleted file mode 100644
index de047eb1..00000000
--- a/adapter/grace/grace.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 grace use to hot reload
-// Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/
-//
-// Usage:
-//
-// import(
-// "log"
-// "net/http"
-// "os"
-//
-// "github.com/beego/beego/v2/server/web/grace"
-// )
-//
-// func handler(w http.ResponseWriter, r *http.Request) {
-// w.Write([]byte("WORLD!"))
-// }
-//
-// func main() {
-// mux := http.NewServeMux()
-// mux.HandleFunc("/hello", handler)
-//
-// err := grace.ListenAndServe("localhost:8080", mux)
-// if err != nil {
-// log.Println(err)
-// }
-// log.Println("Server on 8080 stopped")
-// os.Exit(0)
-// }
-package grace
-
-import (
- "net/http"
- "time"
-
- "github.com/beego/beego/v2/server/web/grace"
-)
-
-const (
- // PreSignal is the position to add filter before signal
- PreSignal = iota
- // PostSignal is the position to add filter after signal
- PostSignal
- // StateInit represent the application inited
- StateInit
- // StateRunning represent the application is running
- StateRunning
- // StateShuttingDown represent the application is shutting down
- StateShuttingDown
- // StateTerminate represent the application is killed
- StateTerminate
-)
-
-var (
-
- // DefaultReadTimeOut is the HTTP read timeout
- DefaultReadTimeOut time.Duration
- // DefaultWriteTimeOut is the HTTP Write timeout
- DefaultWriteTimeOut time.Duration
- // DefaultMaxHeaderBytes is the Max HTTP Header size, default is 0, no limit
- DefaultMaxHeaderBytes int
- // DefaultTimeout is the shutdown server's timeout. default is 60s
- DefaultTimeout = grace.DefaultTimeout
-)
-
-// NewServer returns a new graceServer.
-func NewServer(addr string, handler http.Handler) (srv *Server) {
- return (*Server)(grace.NewServer(addr, handler))
-}
-
-// ListenAndServe refer http.ListenAndServe
-func ListenAndServe(addr string, handler http.Handler) error {
- server := NewServer(addr, handler)
- return server.ListenAndServe()
-}
-
-// ListenAndServeTLS refer http.ListenAndServeTLS
-func ListenAndServeTLS(addr string, certFile string, keyFile string, handler http.Handler) error {
- server := NewServer(addr, handler)
- return server.ListenAndServeTLS(certFile, keyFile)
-}
diff --git a/adapter/grace/server.go b/adapter/grace/server.go
deleted file mode 100644
index 95ca05b4..00000000
--- a/adapter/grace/server.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package grace
-
-import (
- "os"
-
- "github.com/beego/beego/v2/server/web/grace"
-)
-
-// Server embedded http.Server
-type Server grace.Server
-
-// Serve accepts incoming connections on the Listener l,
-// creating a new service goroutine for each.
-// The service goroutines read requests and then call srv.Handler to reply to them.
-func (srv *Server) Serve() (err error) {
- return (*grace.Server)(srv).Serve()
-}
-
-// ListenAndServe listens on the TCP network address srv.Addr and then calls Serve
-// to handle requests on incoming connections. If srv.Addr is blank, ":http" is
-// used.
-func (srv *Server) ListenAndServe() (err error) {
- return (*grace.Server)(srv).ListenAndServe()
-}
-
-// ListenAndServeTLS listens on the TCP network address srv.Addr and then calls
-// Serve to handle requests on incoming TLS connections.
-//
-// Filenames containing a certificate and matching private key for the server must
-// be provided. If the certificate is signed by a certificate authority, the
-// certFile should be the concatenation of the server's certificate followed by the
-// CA's certificate.
-//
-// If srv.Addr is blank, ":https" is used.
-func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
- return (*grace.Server)(srv).ListenAndServeTLS(certFile, keyFile)
-}
-
-// ListenAndServeMutualTLS listens on the TCP network address srv.Addr and then calls
-// Serve to handle requests on incoming mutual TLS connections.
-func (srv *Server) ListenAndServeMutualTLS(certFile, keyFile, trustFile string) error {
- return (*grace.Server)(srv).ListenAndServeMutualTLS(certFile, keyFile, trustFile)
-}
-
-// RegisterSignalHook registers a function to be run PreSignal or PostSignal for a given signal.
-func (srv *Server) RegisterSignalHook(ppFlag int, sig os.Signal, f func()) error {
- return (*grace.Server)(srv).RegisterSignalHook(ppFlag, sig, f)
-}
diff --git a/adapter/httplib/httplib.go b/adapter/httplib/httplib.go
deleted file mode 100644
index 9b0cfe26..00000000
--- a/adapter/httplib/httplib.go
+++ /dev/null
@@ -1,282 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 httplib is used as http.Client
-// Usage:
-//
-// import "github.com/beego/beego/v2/client/httplib"
-//
-// b := httplib.Post("http://beego.vip/")
-// b.Param("username","astaxie")
-// b.Param("password","123456")
-// b.PostFile("uploadfile1", "httplib.pdf")
-// b.PostFile("uploadfile2", "httplib.txt")
-// str, err := b.String()
-// if err != nil {
-// t.Fatal(err)
-// }
-// fmt.Println(str)
-//
-package httplib
-
-import (
- "crypto/tls"
- "net"
- "net/http"
- "net/url"
- "time"
-
- "github.com/beego/beego/v2/client/httplib"
-)
-
-// SetDefaultSetting Overwrite default settings
-func SetDefaultSetting(setting BeegoHTTPSettings) {
- httplib.SetDefaultSetting(httplib.BeegoHTTPSettings(setting))
-}
-
-// NewBeegoRequest return *BeegoHttpRequest with specific method
-func NewBeegoRequest(rawurl, method string) *BeegoHTTPRequest {
- return &BeegoHTTPRequest{
- delegate: httplib.NewBeegoRequest(rawurl, method),
- }
-}
-
-// Get returns *BeegoHttpRequest with GET method.
-func Get(url string) *BeegoHTTPRequest {
- return NewBeegoRequest(url, "GET")
-}
-
-// Post returns *BeegoHttpRequest with POST method.
-func Post(url string) *BeegoHTTPRequest {
- return NewBeegoRequest(url, "POST")
-}
-
-// Put returns *BeegoHttpRequest with PUT method.
-func Put(url string) *BeegoHTTPRequest {
- return NewBeegoRequest(url, "PUT")
-}
-
-// Delete returns *BeegoHttpRequest DELETE method.
-func Delete(url string) *BeegoHTTPRequest {
- return NewBeegoRequest(url, "DELETE")
-}
-
-// Head returns *BeegoHttpRequest with HEAD method.
-func Head(url string) *BeegoHTTPRequest {
- return NewBeegoRequest(url, "HEAD")
-}
-
-// BeegoHTTPSettings is the http.Client setting
-type BeegoHTTPSettings httplib.BeegoHTTPSettings
-
-// BeegoHTTPRequest provides more useful methods for requesting one url than http.Request.
-type BeegoHTTPRequest struct {
- delegate *httplib.BeegoHTTPRequest
-}
-
-// GetRequest return the request object
-func (b *BeegoHTTPRequest) GetRequest() *http.Request {
- return b.delegate.GetRequest()
-}
-
-// Setting Change request settings
-func (b *BeegoHTTPRequest) Setting(setting BeegoHTTPSettings) *BeegoHTTPRequest {
- b.delegate.Setting(httplib.BeegoHTTPSettings(setting))
- return b
-}
-
-// SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
-func (b *BeegoHTTPRequest) SetBasicAuth(username, password string) *BeegoHTTPRequest {
- b.delegate.SetBasicAuth(username, password)
- return b
-}
-
-// SetEnableCookie sets enable/disable cookiejar
-func (b *BeegoHTTPRequest) SetEnableCookie(enable bool) *BeegoHTTPRequest {
- b.delegate.SetEnableCookie(enable)
- return b
-}
-
-// SetUserAgent sets User-Agent header field
-func (b *BeegoHTTPRequest) SetUserAgent(useragent string) *BeegoHTTPRequest {
- b.delegate.SetUserAgent(useragent)
- return b
-}
-
-// Retries sets Retries times.
-// default is 0 means no retried.
-// -1 means retried forever.
-// others means retried times.
-func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest {
- b.delegate.Retries(times)
- return b
-}
-
-func (b *BeegoHTTPRequest) RetryDelay(delay time.Duration) *BeegoHTTPRequest {
- b.delegate.RetryDelay(delay)
- return b
-}
-
-// SetTimeout sets connect time out and read-write time out for BeegoRequest.
-func (b *BeegoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHTTPRequest {
- b.delegate.SetTimeout(connectTimeout, readWriteTimeout)
- return b
-}
-
-// SetTLSClientConfig sets tls connection configurations if visiting https url.
-func (b *BeegoHTTPRequest) SetTLSClientConfig(config *tls.Config) *BeegoHTTPRequest {
- b.delegate.SetTLSClientConfig(config)
- return b
-}
-
-// Header add header item string in request.
-func (b *BeegoHTTPRequest) Header(key, value string) *BeegoHTTPRequest {
- b.delegate.Header(key, value)
- return b
-}
-
-// SetHost set the request host
-func (b *BeegoHTTPRequest) SetHost(host string) *BeegoHTTPRequest {
- b.delegate.SetHost(host)
- return b
-}
-
-// SetProtocolVersion Set the protocol version for incoming requests.
-// Client requests always use HTTP/1.1.
-func (b *BeegoHTTPRequest) SetProtocolVersion(vers string) *BeegoHTTPRequest {
- b.delegate.SetProtocolVersion(vers)
- return b
-}
-
-// SetCookie add cookie into request.
-func (b *BeegoHTTPRequest) SetCookie(cookie *http.Cookie) *BeegoHTTPRequest {
- b.delegate.SetCookie(cookie)
- return b
-}
-
-// SetTransport set the setting transport
-func (b *BeegoHTTPRequest) SetTransport(transport http.RoundTripper) *BeegoHTTPRequest {
- b.delegate.SetTransport(transport)
- return b
-}
-
-// SetProxy set the http proxy
-// example:
-//
-// func(req *http.Request) (*url.URL, error) {
-// u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
-// return u, nil
-// }
-func (b *BeegoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHTTPRequest {
- b.delegate.SetProxy(proxy)
- return b
-}
-
-// SetCheckRedirect specifies the policy for handling redirects.
-//
-// If CheckRedirect is nil, the Client uses its default policy,
-// which is to stop after 10 consecutive requests.
-func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest {
- b.delegate.SetCheckRedirect(redirect)
- return b
-}
-
-// Param adds query param in to request.
-// params build query string as ?key1=value1&key2=value2...
-func (b *BeegoHTTPRequest) Param(key, value string) *BeegoHTTPRequest {
- b.delegate.Param(key, value)
- return b
-}
-
-// PostFile add a post file to the request
-func (b *BeegoHTTPRequest) PostFile(formname, filename string) *BeegoHTTPRequest {
- b.delegate.PostFile(formname, filename)
- return b
-}
-
-// Body adds request raw body.
-// it supports string and []byte.
-func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest {
- b.delegate.Body(data)
- return b
-}
-
-// XMLBody adds request raw body encoding by XML.
-func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error) {
- _, err := b.delegate.XMLBody(obj)
- return b, err
-}
-
-// YAMLBody adds request raw body encoding by YAML.
-func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error) {
- _, err := b.delegate.YAMLBody(obj)
- return b, err
-}
-
-// JSONBody adds request raw body encoding by JSON.
-func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error) {
- _, err := b.delegate.JSONBody(obj)
- return b, err
-}
-
-// DoRequest will do the client.Do
-func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error) {
- return b.delegate.DoRequest()
-}
-
-// String returns the body string in response.
-// it calls Response inner.
-func (b *BeegoHTTPRequest) String() (string, error) {
- return b.delegate.String()
-}
-
-// Bytes returns the body []byte in response.
-// it calls Response inner.
-func (b *BeegoHTTPRequest) Bytes() ([]byte, error) {
- return b.delegate.Bytes()
-}
-
-// ToFile saves the body data in response to one file.
-// it calls Response inner.
-func (b *BeegoHTTPRequest) ToFile(filename string) error {
- return b.delegate.ToFile(filename)
-}
-
-// ToJSON returns the map that marshals from the body bytes as json in response .
-// it calls Response inner.
-func (b *BeegoHTTPRequest) ToJSON(v interface{}) error {
- return b.delegate.ToJSON(v)
-}
-
-// ToXML returns the map that marshals from the body bytes as xml in response .
-// it calls Response inner.
-func (b *BeegoHTTPRequest) ToXML(v interface{}) error {
- return b.delegate.ToXML(v)
-}
-
-// ToYAML returns the map that marshals from the body bytes as yaml in response .
-// it calls Response inner.
-func (b *BeegoHTTPRequest) ToYAML(v interface{}) error {
- return b.delegate.ToYAML(v)
-}
-
-// Response executes request client gets response mannually.
-func (b *BeegoHTTPRequest) Response() (*http.Response, error) {
- return b.delegate.Response()
-}
-
-// TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
-func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
- return httplib.TimeoutDialer(cTimeout, rwTimeout)
-}
diff --git a/adapter/httplib/httplib_test.go b/adapter/httplib/httplib_test.go
deleted file mode 100644
index 41018c19..00000000
--- a/adapter/httplib/httplib_test.go
+++ /dev/null
@@ -1,290 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 httplib
-
-import (
- "bytes"
- "errors"
- "io/ioutil"
- "net"
- "net/http"
- "os"
- "strings"
- "testing"
- "time"
-)
-
-const (
- getURL = "http://httpbin.org/get"
- ipURL = "http://httpbin.org/ip"
-)
-
-func TestResponse(t *testing.T) {
- req := Get(getURL)
- resp, err := req.Response()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(resp)
-}
-
-func TestDoRequest(t *testing.T) {
- req := Get("https://goolnk.com/33BD2j")
- retryAmount := 1
- req.Retries(1)
- req.RetryDelay(1400 * time.Millisecond)
- retryDelay := 1400 * time.Millisecond
-
- req.SetCheckRedirect(func(redirectReq *http.Request, redirectVia []*http.Request) error {
- return errors.New("Redirect triggered")
- })
-
- startTime := time.Now().UnixNano() / int64(time.Millisecond)
-
- _, err := req.Response()
- if err == nil {
- t.Fatal("Response should have yielded an error")
- }
-
- endTime := time.Now().UnixNano() / int64(time.Millisecond)
- elapsedTime := endTime - startTime
- delayedTime := int64(retryAmount) * retryDelay.Milliseconds()
-
- if elapsedTime < delayedTime {
- t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime)
- }
-}
-
-func TestGet(t *testing.T) {
- req := Get(getURL)
- b, err := req.Bytes()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(b)
-
- s, err := req.String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(s)
-
- if string(b) != s {
- t.Fatal("request data not match")
- }
-}
-
-func TestSimplePost(t *testing.T) {
- v := "smallfish"
- req := Post("http://httpbin.org/post")
- req.Param("username", v)
-
- str, err := req.String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-
- n := strings.Index(str, v)
- if n == -1 {
- t.Fatal(v + " not found in post")
- }
-}
-
-// func TestPostFile(t *testing.T) {
-// v := "smallfish"
-// req := Post("http://httpbin.org/post")
-// req.Debug(true)
-// req.Param("username", v)
-// req.PostFile("uploadfile", "httplib_test.go")
-
-// str, err := req.String()
-// if err != nil {
-// t.Fatal(err)
-// }
-// t.Log(str)
-
-// n := strings.Index(str, v)
-// if n == -1 {
-// t.Fatal(v + " not found in post")
-// }
-// }
-
-func TestSimplePut(t *testing.T) {
- str, err := Put("http://httpbin.org/put").String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-}
-
-func TestSimpleDelete(t *testing.T) {
- str, err := Delete("http://httpbin.org/delete").String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-}
-
-func TestSimpleDeleteParam(t *testing.T) {
- str, err := Delete("http://httpbin.org/delete").Param("key", "val").String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-}
-
-func TestWithCookie(t *testing.T) {
- v := "smallfish"
- str, err := Get("http://httpbin.org/cookies/set?k1=" + v).SetEnableCookie(true).String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-
- str, err = Get("http://httpbin.org/cookies").SetEnableCookie(true).String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-
- n := strings.Index(str, v)
- if n == -1 {
- t.Fatal(v + " not found in cookie")
- }
-}
-
-func TestWithBasicAuth(t *testing.T) {
- str, err := Get("http://httpbin.org/basic-auth/user/passwd").SetBasicAuth("user", "passwd").String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
- n := strings.Index(str, "authenticated")
- if n == -1 {
- t.Fatal("authenticated not found in response")
- }
-}
-
-func TestWithUserAgent(t *testing.T) {
- v := "beego"
- str, err := Get("http://httpbin.org/headers").SetUserAgent(v).String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-
- n := strings.Index(str, v)
- if n == -1 {
- t.Fatal(v + " not found in user-agent")
- }
-}
-
-func TestWithSetting(t *testing.T) {
- v := "beego"
- var setting BeegoHTTPSettings
- setting.EnableCookie = true
- setting.UserAgent = v
- setting.Transport = &http.Transport{
- DialContext: (&net.Dialer{
- Timeout: 30 * time.Second,
- KeepAlive: 30 * time.Second,
- DualStack: true,
- }).DialContext,
- MaxIdleConns: 50,
- IdleConnTimeout: 90 * time.Second,
- ExpectContinueTimeout: 1 * time.Second,
- }
- setting.ReadWriteTimeout = 5 * time.Second
- SetDefaultSetting(setting)
-
- str, err := Get(getURL).String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-
- n := strings.Index(str, v)
- if n == -1 {
- t.Fatal(v + " not found in user-agent")
- }
-}
-
-func TestToJson(t *testing.T) {
- req := Get(ipURL)
- resp, err := req.Response()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(resp)
-
- // httpbin will return http remote addr
- type IP struct {
- Origin string `json:"origin"`
- }
- var ip IP
- err = req.ToJSON(&ip)
- if err != nil {
- t.Fatal(err)
- }
- t.Log(ip.Origin)
- ips := strings.Split(ip.Origin, ",")
- if len(ips) == 0 {
- t.Fatal("response is not valid ip")
- }
- for i := range ips {
- if net.ParseIP(strings.TrimSpace(ips[i])).To4() == nil {
- t.Fatal("response is not valid ip")
- }
- }
-}
-
-func TestToFile(t *testing.T) {
- f := "beego_testfile"
- req := Get(ipURL)
- err := req.ToFile(f)
- if err != nil {
- t.Fatal(err)
- }
- defer os.Remove(f)
- b, err := ioutil.ReadFile(f)
- if n := bytes.Index(b, []byte("origin")); n == -1 {
- t.Fatal(err)
- }
-}
-
-func TestToFileDir(t *testing.T) {
- f := "./files/beego_testfile"
- req := Get(ipURL)
- err := req.ToFile(f)
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll("./files")
- b, err := ioutil.ReadFile(f)
- if n := bytes.Index(b, []byte("origin")); n == -1 {
- t.Fatal(err)
- }
-}
-
-func TestHeader(t *testing.T) {
- req := Get("http://httpbin.org/headers")
- req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36")
- str, err := req.String()
- if err != nil {
- t.Fatal(err)
- }
- t.Log(str)
-}
diff --git a/adapter/log.go b/adapter/log.go
deleted file mode 100644
index 9fc3a551..00000000
--- a/adapter/log.go
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "strings"
-
- "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 = 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.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-var BeeLogger = logs.GetBeeLogger()
-
-// SetLevel sets the global log level used by the simple logger.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func SetLevel(l int) {
- logs.SetLevel(l)
-}
-
-// SetLogFuncCall set the CallDepth, default is 3
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func SetLogFuncCall(b bool) {
- logs.SetLogFuncCall(b)
-}
-
-// SetLogger sets a new logger.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func SetLogger(adaptername string, config string) error {
- return logs.SetLogger(adaptername, config)
-}
-
-// Emergency logs a message at emergency level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Emergency(v ...interface{}) {
- logs.Emergency(generateFmtStr(len(v)), v...)
-}
-
-// Alert logs a message at alert level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Alert(v ...interface{}) {
- logs.Alert(generateFmtStr(len(v)), v...)
-}
-
-// Critical logs a message at critical level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Critical(v ...interface{}) {
- logs.Critical(generateFmtStr(len(v)), v...)
-}
-
-// Error logs a message at error level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Error(v ...interface{}) {
- logs.Error(generateFmtStr(len(v)), v...)
-}
-
-// Warning logs a message at warning level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Warning(v ...interface{}) {
- logs.Warning(generateFmtStr(len(v)), v...)
-}
-
-// Warn compatibility alias for Warning()
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Warn(v ...interface{}) {
- logs.Warn(generateFmtStr(len(v)), v...)
-}
-
-// Notice logs a message at notice level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Notice(v ...interface{}) {
- logs.Notice(generateFmtStr(len(v)), v...)
-}
-
-// Informational logs a message at info level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Informational(v ...interface{}) {
- logs.Informational(generateFmtStr(len(v)), v...)
-}
-
-// Info compatibility alias for Warning()
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Info(v ...interface{}) {
- logs.Info(generateFmtStr(len(v)), v...)
-}
-
-// Debug logs a message at debug level.
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Debug(v ...interface{}) {
- logs.Debug(generateFmtStr(len(v)), v...)
-}
-
-// Trace logs a message at trace level.
-// compatibility alias for Warning()
-// Deprecated: use github.com/beego/beego/v2/core/logs instead.
-func Trace(v ...interface{}) {
- logs.Trace(generateFmtStr(len(v)), v...)
-}
-
-func generateFmtStr(n int) string {
- return strings.Repeat("%v ", n)
-}
diff --git a/adapter/logs/accesslog.go b/adapter/logs/accesslog.go
deleted file mode 100644
index f4370a5d..00000000
--- a/adapter/logs/accesslog.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 logs
-
-import (
- "github.com/beego/beego/v2/core/logs"
-)
-
-// AccessLogRecord struct for holding access log data.
-type AccessLogRecord logs.AccessLogRecord
-
-// AccessLog - Format and print access log.
-func AccessLog(r *AccessLogRecord, format string) {
- logs.AccessLog((*logs.AccessLogRecord)(r), format)
-}
diff --git a/adapter/logs/alils/alils.go b/adapter/logs/alils/alils.go
deleted file mode 100644
index 2f700457..00000000
--- a/adapter/logs/alils/alils.go
+++ /dev/null
@@ -1,5 +0,0 @@
-package alils
-
-import (
- _ "github.com/beego/beego/v2/core/logs/alils"
-)
diff --git a/adapter/logs/es/es.go b/adapter/logs/es/es.go
deleted file mode 100644
index 124e3fdd..00000000
--- a/adapter/logs/es/es.go
+++ /dev/null
@@ -1,5 +0,0 @@
-package es
-
-import (
- _ "github.com/beego/beego/v2/core/logs/es"
-)
diff --git a/adapter/logs/log.go b/adapter/logs/log.go
deleted file mode 100644
index a040a1f5..00000000
--- a/adapter/logs/log.go
+++ /dev/null
@@ -1,346 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 logs provide a general log interface
-// Usage:
-//
-// import "github.com/beego/beego/v2/core/logs"
-//
-// log := NewLogger(10000)
-// log.SetLogger("console", "")
-//
-// > the first params stand for how many channel
-//
-// Use it like this:
-//
-// log.Trace("trace")
-// log.Info("info")
-// log.Warn("warning")
-// log.Debug("debug")
-// log.Critical("critical")
-//
-package logs
-
-import (
- "log"
- "time"
-
- "github.com/beego/beego/v2/core/logs"
-)
-
-// RFC5424 log message levels.
-const (
- LevelEmergency = iota
- LevelAlert
- LevelCritical
- LevelError
- LevelWarning
- LevelNotice
- LevelInformational
- LevelDebug
-)
-
-// levelLogLogger is defined to implement log.Logger
-// the real log level will be LevelEmergency
-const levelLoggerImpl = -1
-
-// Name for adapter with beego official support
-const (
- AdapterConsole = "console"
- AdapterFile = "file"
- AdapterMultiFile = "multifile"
- AdapterMail = "smtp"
- AdapterConn = "conn"
- AdapterEs = "es"
- AdapterJianLiao = "jianliao"
- AdapterSlack = "slack"
- AdapterAliLS = "alils"
-)
-
-// Legacy log level constants to ensure backwards compatibility.
-const (
- LevelInfo = LevelInformational
- LevelTrace = LevelDebug
- LevelWarn = LevelWarning
-)
-
-type newLoggerFunc func() Logger
-
-// Logger defines the behavior of a log provider.
-type Logger interface {
- Init(config string) error
- WriteMsg(when time.Time, msg string, level int) error
- Destroy()
- Flush()
-}
-
-// Register makes a log provide available by the provided name.
-// If Register is called twice with the same name or if driver is nil,
-// it panics.
-func Register(name string, log newLoggerFunc) {
- logs.Register(name, func() logs.Logger {
- return &oldToNewAdapter{
- old: log(),
- }
- })
-}
-
-// BeeLogger is default logger in beego application.
-// it can contain several providers and log message into all providers.
-type BeeLogger logs.BeeLogger
-
-const defaultAsyncMsgLen = 1e3
-
-// NewLogger returns a new BeeLogger.
-// channelLen means the number of messages in chan(used where asynchronous is true).
-// if the buffering chan is full, logger adapters write to file or other way.
-func NewLogger(channelLens ...int64) *BeeLogger {
- return (*BeeLogger)(logs.NewLogger(channelLens...))
-}
-
-// Async set the log to asynchronous and start the goroutine
-func (bl *BeeLogger) Async(msgLen ...int64) *BeeLogger {
- (*logs.BeeLogger)(bl).Async(msgLen...)
- return bl
-}
-
-// SetLogger provides a given logger adapter into BeeLogger with config string.
-// config need to be correct JSON as string: {"interval":360}.
-func (bl *BeeLogger) SetLogger(adapterName string, configs ...string) error {
- return (*logs.BeeLogger)(bl).SetLogger(adapterName, configs...)
-}
-
-// DelLogger remove a logger adapter in BeeLogger.
-func (bl *BeeLogger) DelLogger(adapterName string) error {
- return (*logs.BeeLogger)(bl).DelLogger(adapterName)
-}
-
-func (bl *BeeLogger) Write(p []byte) (n int, err error) {
- return (*logs.BeeLogger)(bl).Write(p)
-}
-
-// SetLevel Set log message level.
-// If message level (such as LevelDebug) is higher than logger level (such as LevelWarning),
-// log providers will not even be sent the message.
-func (bl *BeeLogger) SetLevel(l int) {
- (*logs.BeeLogger)(bl).SetLevel(l)
-}
-
-// GetLevel Get Current log message level.
-func (bl *BeeLogger) GetLevel() int {
- return (*logs.BeeLogger)(bl).GetLevel()
-}
-
-// SetLogFuncCallDepth set log funcCallDepth
-func (bl *BeeLogger) SetLogFuncCallDepth(d int) {
- (*logs.BeeLogger)(bl).SetLogFuncCallDepth(d)
-}
-
-// GetLogFuncCallDepth return log funcCallDepth for wrapper
-func (bl *BeeLogger) GetLogFuncCallDepth() int {
- return (*logs.BeeLogger)(bl).GetLogFuncCallDepth()
-}
-
-// EnableFuncCallDepth enable log funcCallDepth
-func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
- (*logs.BeeLogger)(bl).EnableFuncCallDepth(b)
-}
-
-// SetPrefix will set prefix
-func (bl *BeeLogger) SetPrefix(s string) {
- (*logs.BeeLogger)(bl).SetPrefix(s)
-}
-
-// Emergency Log EMERGENCY level message.
-func (bl *BeeLogger) Emergency(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Emergency(format, v...)
-}
-
-// Alert Log ALERT level message.
-func (bl *BeeLogger) Alert(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Alert(format, v...)
-}
-
-// Critical Log CRITICAL level message.
-func (bl *BeeLogger) Critical(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Critical(format, v...)
-}
-
-// Error Log ERROR level message.
-func (bl *BeeLogger) Error(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Error(format, v...)
-}
-
-// Warning Log WARNING level message.
-func (bl *BeeLogger) Warning(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Warning(format, v...)
-}
-
-// Notice Log NOTICE level message.
-func (bl *BeeLogger) Notice(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Notice(format, v...)
-}
-
-// Informational Log INFORMATIONAL level message.
-func (bl *BeeLogger) Informational(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Informational(format, v...)
-}
-
-// Debug Log DEBUG level message.
-func (bl *BeeLogger) Debug(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Debug(format, v...)
-}
-
-// Warn Log WARN level message.
-// compatibility alias for Warning()
-func (bl *BeeLogger) Warn(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Warn(format, v...)
-}
-
-// Info Log INFO level message.
-// compatibility alias for Informational()
-func (bl *BeeLogger) Info(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Info(format, v...)
-}
-
-// Trace Log TRACE level message.
-// compatibility alias for Debug()
-func (bl *BeeLogger) Trace(format string, v ...interface{}) {
- (*logs.BeeLogger)(bl).Trace(format, v...)
-}
-
-// Flush flush all chan data.
-func (bl *BeeLogger) Flush() {
- (*logs.BeeLogger)(bl).Flush()
-}
-
-// Close close logger, flush all chan data and destroy all adapters in BeeLogger.
-func (bl *BeeLogger) Close() {
- (*logs.BeeLogger)(bl).Close()
-}
-
-// Reset close all outputs, and set bl.outputs to nil
-func (bl *BeeLogger) Reset() {
- (*logs.BeeLogger)(bl).Reset()
-}
-
-// GetBeeLogger returns the default BeeLogger
-func GetBeeLogger() *BeeLogger {
- return (*BeeLogger)(logs.GetBeeLogger())
-}
-
-// GetLogger returns the default BeeLogger
-func GetLogger(prefixes ...string) *log.Logger {
- return logs.GetLogger(prefixes...)
-}
-
-// Reset will remove all the adapter
-func Reset() {
- logs.Reset()
-}
-
-// Async set the beelogger with Async mode and hold msglen messages
-func Async(msgLen ...int64) *BeeLogger {
- return (*BeeLogger)(logs.Async(msgLen...))
-}
-
-// SetLevel sets the global log level used by the simple logger.
-func SetLevel(l int) {
- logs.SetLevel(l)
-}
-
-// SetPrefix sets the prefix
-func SetPrefix(s string) {
- logs.SetPrefix(s)
-}
-
-// EnableFuncCallDepth enable log funcCallDepth
-func EnableFuncCallDepth(b bool) {
- logs.EnableFuncCallDepth(b)
-}
-
-// SetLogFuncCall set the CallDepth, default is 4
-func SetLogFuncCall(b bool) {
- logs.SetLogFuncCall(b)
-}
-
-// SetLogFuncCallDepth set log funcCallDepth
-func SetLogFuncCallDepth(d int) {
- logs.SetLogFuncCallDepth(d)
-}
-
-// SetLogger sets a new logger.
-func SetLogger(adapter string, config ...string) error {
- return logs.SetLogger(adapter, config...)
-}
-
-// Emergency logs a message at emergency level.
-func Emergency(f interface{}, v ...interface{}) {
- logs.Emergency(f, v...)
-}
-
-// Alert logs a message at alert level.
-func Alert(f interface{}, v ...interface{}) {
- logs.Alert(f, v...)
-}
-
-// Critical logs a message at critical level.
-func Critical(f interface{}, v ...interface{}) {
- logs.Critical(f, v...)
-}
-
-// Error logs a message at error level.
-func Error(f interface{}, v ...interface{}) {
- logs.Error(f, v...)
-}
-
-// Warning logs a message at warning level.
-func Warning(f interface{}, v ...interface{}) {
- logs.Warning(f, v...)
-}
-
-// Warn compatibility alias for Warning()
-func Warn(f interface{}, v ...interface{}) {
- logs.Warn(f, v...)
-}
-
-// Notice logs a message at notice level.
-func Notice(f interface{}, v ...interface{}) {
- logs.Notice(f, v...)
-}
-
-// Informational logs a message at info level.
-func Informational(f interface{}, v ...interface{}) {
- logs.Informational(f, v...)
-}
-
-// Info compatibility alias for Warning()
-func Info(f interface{}, v ...interface{}) {
- logs.Info(f, v...)
-}
-
-// Debug logs a message at debug level.
-func Debug(f interface{}, v ...interface{}) {
- logs.Debug(f, v...)
-}
-
-// Trace logs a message at trace level.
-// compatibility alias for Warning()
-func Trace(f interface{}, v ...interface{}) {
- logs.Trace(f, v...)
-}
-
-func init() {
- SetLogFuncCallDepth(4)
-}
diff --git a/adapter/logs/log_adapter.go b/adapter/logs/log_adapter.go
deleted file mode 100644
index 6affe8ff..00000000
--- a/adapter/logs/log_adapter.go
+++ /dev/null
@@ -1,43 +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 logs
-
-import (
- "github.com/beego/beego/v2/core/logs"
-)
-
-type oldToNewAdapter struct {
- old Logger
-}
-
-func (o *oldToNewAdapter) Init(config string) error {
- return o.old.Init(config)
-}
-
-func (o *oldToNewAdapter) WriteMsg(lm *logs.LogMsg) error {
- return o.old.WriteMsg(lm.When, lm.OldStyleFormat(), lm.Level)
-}
-
-func (o *oldToNewAdapter) Destroy() {
- o.old.Destroy()
-}
-
-func (o *oldToNewAdapter) Flush() {
- o.old.Flush()
-}
-
-func (*oldToNewAdapter) SetFormatter(f logs.LogFormatter) {
- panic("unsupported operation, you should not invoke this method")
-}
diff --git a/adapter/logs/logger.go b/adapter/logs/logger.go
deleted file mode 100644
index 58bdfc30..00000000
--- a/adapter/logs/logger.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 logs
-
-import (
- "github.com/beego/beego/v2/core/logs"
-)
-
-// ColorByStatus return color by http code
-// 2xx return Green
-// 3xx return White
-// 4xx return Yellow
-// 5xx return Red
-func ColorByStatus(code int) string {
- return logs.ColorByStatus(code)
-}
-
-// ColorByMethod return color by http code
-func ColorByMethod(method string) string {
- return logs.ColorByMethod(method)
-}
-
-// ResetColor return reset color
-func ResetColor() string {
- return logs.ResetColor()
-}
diff --git a/adapter/logs/logger_test.go b/adapter/logs/logger_test.go
deleted file mode 100644
index 42708fa5..00000000
--- a/adapter/logs/logger_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2016 beego Author. All Rights Reserved.
-//
-// 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 logs
-
-import (
- "testing"
-)
-
-func TestBeeLoggerInfo(t *testing.T) {
- log := NewLogger(1000)
- log.SetLogger("file", `{"net":"tcp","addr":":7020"}`)
-}
diff --git a/adapter/metric/prometheus.go b/adapter/metric/prometheus.go
deleted file mode 100644
index 6b276171..00000000
--- a/adapter/metric/prometheus.go
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright 2020 astaxie
-//
-// 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 metric
-
-import (
- "net/http"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "github.com/prometheus/client_golang/prometheus"
-
- "github.com/beego/beego/v2"
- "github.com/beego/beego/v2/core/logs"
- "github.com/beego/beego/v2/server/web"
-)
-
-func PrometheusMiddleWare(next http.Handler) http.Handler {
- summaryVec := prometheus.NewSummaryVec(prometheus.SummaryOpts{
- Name: "beego",
- Subsystem: "http_request",
- ConstLabels: map[string]string{
- "server": web.BConfig.ServerName,
- "env": web.BConfig.RunMode,
- "appname": web.BConfig.AppName,
- },
- Help: "The statics info for http request",
- }, []string{"pattern", "method", "status"})
-
- prometheus.MustRegister(summaryVec)
-
- registerBuildInfo()
-
- return http.HandlerFunc(func(writer http.ResponseWriter, q *http.Request) {
- start := time.Now()
- next.ServeHTTP(writer, q)
- end := time.Now()
- go report(end.Sub(start), writer, q, summaryVec)
- })
-}
-
-func registerBuildInfo() {
- buildInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{
- Name: "beego",
- Subsystem: "build_info",
- Help: "The building information",
- ConstLabels: map[string]string{
- "appname": web.BConfig.AppName,
- "build_version": beego.BuildVersion,
- "build_revision": beego.BuildGitRevision,
- "build_status": beego.BuildStatus,
- "build_tag": beego.BuildTag,
- "build_time": strings.Replace(beego.BuildTime, "--", " ", 1),
- "go_version": beego.GoVersion,
- "git_branch": beego.GitBranch,
- "start_time": time.Now().Format("2006-01-02 15:04:05"),
- },
- }, []string{})
-
- prometheus.MustRegister(buildInfo)
- buildInfo.WithLabelValues().Set(1)
-}
-
-func report(dur time.Duration, writer http.ResponseWriter, q *http.Request, vec *prometheus.SummaryVec) {
- ctrl := web.BeeApp.Handlers
- ctx := ctrl.GetContext()
- ctx.Reset(writer, q)
- defer ctrl.GiveBackContext(ctx)
-
- // We cannot read the status code from q.Response.StatusCode
- // since the http server does not set q.Response. So q.Response is nil
- // Thus, we use reflection to read the status from writer whose concrete type is http.response
- responseVal := reflect.ValueOf(writer).Elem()
- field := responseVal.FieldByName("status")
- status := -1
- if field.IsValid() && field.Kind() == reflect.Int {
- status = int(field.Int())
- }
- ptn := "UNKNOWN"
- if rt, found := ctrl.FindRouter(ctx); found {
- ptn = rt.GetPattern()
- } else {
- logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String())
- }
- ms := dur / time.Millisecond
- vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status)).Observe(float64(ms))
-}
diff --git a/adapter/metric/prometheus_test.go b/adapter/metric/prometheus_test.go
deleted file mode 100644
index 72212dd4..00000000
--- a/adapter/metric/prometheus_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2020 astaxie
-//
-// 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 metric
-
-import (
- "fmt"
- "net/http"
- "net/url"
- "testing"
- "time"
-
- "github.com/prometheus/client_golang/prometheus"
-
- "github.com/beego/beego/v2/adapter/context"
-)
-
-func TestPrometheusMiddleWare(t *testing.T) {
- middleware := PrometheusMiddleWare(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
- fmt.Print("you are coming")
- }))
- writer := &context.Response{}
- request := &http.Request{
- URL: &url.URL{
- Host: "localhost",
- RawPath: "/a/b/c",
- },
- Method: "POST",
- }
- vec := prometheus.NewSummaryVec(prometheus.SummaryOpts{}, []string{"pattern", "method", "status"})
-
- report(time.Second, writer, request, vec)
- middleware.ServeHTTP(writer, request)
-}
diff --git a/adapter/migration/ddl.go b/adapter/migration/ddl.go
deleted file mode 100644
index 93be2d7d..00000000
--- a/adapter/migration/ddl.go
+++ /dev/null
@@ -1,198 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 migration
-
-import (
- "github.com/beego/beego/v2/client/orm/migration"
-)
-
-// Index struct defines the structure of Index Columns
-type Index migration.Index
-
-// Unique struct defines a single unique key combination
-type Unique migration.Unique
-
-// Column struct defines a single column of a table
-type Column migration.Column
-
-// Foreign struct defines a single foreign relationship
-type Foreign migration.Foreign
-
-// RenameColumn struct allows renaming of columns
-type RenameColumn migration.RenameColumn
-
-// CreateTable creates the table on system
-func (m *Migration) CreateTable(tablename, engine, charset string, p ...func()) {
- (*migration.Migration)(m).CreateTable(tablename, engine, charset, p...)
-}
-
-// AlterTable set the ModifyType to alter
-func (m *Migration) AlterTable(tablename string) {
- (*migration.Migration)(m).AlterTable(tablename)
-}
-
-// NewCol creates a new standard column and attaches it to m struct
-func (m *Migration) NewCol(name string) *Column {
- return (*Column)((*migration.Migration)(m).NewCol(name))
-}
-
-// PriCol creates a new primary column and attaches it to m struct
-func (m *Migration) PriCol(name string) *Column {
- return (*Column)((*migration.Migration)(m).PriCol(name))
-}
-
-// UniCol creates / appends columns to specified unique key and attaches it to m struct
-func (m *Migration) UniCol(uni, name string) *Column {
- return (*Column)((*migration.Migration)(m).UniCol(uni, name))
-}
-
-// ForeignCol creates a new foreign column and returns the instance of column
-func (m *Migration) ForeignCol(colname, foreigncol, foreigntable string) (foreign *Foreign) {
- return (*Foreign)((*migration.Migration)(m).ForeignCol(colname, foreigncol, foreigntable))
-}
-
-// SetOnDelete sets the on delete of foreign
-func (foreign *Foreign) SetOnDelete(del string) *Foreign {
- (*migration.Foreign)(foreign).SetOnDelete(del)
- return foreign
-}
-
-// SetOnUpdate sets the on update of foreign
-func (foreign *Foreign) SetOnUpdate(update string) *Foreign {
- (*migration.Foreign)(foreign).SetOnUpdate(update)
- return foreign
-}
-
-// Remove marks the columns to be removed.
-// it allows reverse m to create the column.
-func (c *Column) Remove() {
- (*migration.Column)(c).Remove()
-}
-
-// SetAuto enables auto_increment of column (can be used once)
-func (c *Column) SetAuto(inc bool) *Column {
- (*migration.Column)(c).SetAuto(inc)
- return c
-}
-
-// SetNullable sets the column to be null
-func (c *Column) SetNullable(null bool) *Column {
- (*migration.Column)(c).SetNullable(null)
- return c
-}
-
-// SetDefault sets the default value, prepend with "DEFAULT "
-func (c *Column) SetDefault(def string) *Column {
- (*migration.Column)(c).SetDefault(def)
- return c
-}
-
-// SetUnsigned sets the column to be unsigned int
-func (c *Column) SetUnsigned(unsign bool) *Column {
- (*migration.Column)(c).SetUnsigned(unsign)
- return c
-}
-
-// SetDataType sets the dataType of the column
-func (c *Column) SetDataType(dataType string) *Column {
- (*migration.Column)(c).SetDataType(dataType)
- return c
-}
-
-// SetOldNullable allows reverting to previous nullable on reverse ms
-func (c *RenameColumn) SetOldNullable(null bool) *RenameColumn {
- (*migration.RenameColumn)(c).SetOldNullable(null)
- return c
-}
-
-// SetOldDefault allows reverting to previous default on reverse ms
-func (c *RenameColumn) SetOldDefault(def string) *RenameColumn {
- (*migration.RenameColumn)(c).SetOldDefault(def)
- return c
-}
-
-// SetOldUnsigned allows reverting to previous unsgined on reverse ms
-func (c *RenameColumn) SetOldUnsigned(unsign bool) *RenameColumn {
- (*migration.RenameColumn)(c).SetOldUnsigned(unsign)
- return c
-}
-
-// SetOldDataType allows reverting to previous datatype on reverse ms
-func (c *RenameColumn) SetOldDataType(dataType string) *RenameColumn {
- (*migration.RenameColumn)(c).SetOldDataType(dataType)
- return c
-}
-
-// SetPrimary adds the columns to the primary key (can only be used any number of times in only one m)
-func (c *Column) SetPrimary(m *Migration) *Column {
- (*migration.Column)(c).SetPrimary((*migration.Migration)(m))
- return c
-}
-
-// AddColumnsToUnique adds the columns to Unique Struct
-func (unique *Unique) AddColumnsToUnique(columns ...*Column) *Unique {
- cls := toNewColumnsArray(columns)
- (*migration.Unique)(unique).AddColumnsToUnique(cls...)
- return unique
-}
-
-// AddColumns adds columns to m struct
-func (m *Migration) AddColumns(columns ...*Column) *Migration {
- cls := toNewColumnsArray(columns)
- (*migration.Migration)(m).AddColumns(cls...)
- return m
-}
-
-func toNewColumnsArray(columns []*Column) []*migration.Column {
- cls := make([]*migration.Column, 0, len(columns))
- for _, c := range columns {
- cls = append(cls, (*migration.Column)(c))
- }
- return cls
-}
-
-// AddPrimary adds the column to primary in m struct
-func (m *Migration) AddPrimary(primary *Column) *Migration {
- (*migration.Migration)(m).AddPrimary((*migration.Column)(primary))
- return m
-}
-
-// AddUnique adds the column to unique in m struct
-func (m *Migration) AddUnique(unique *Unique) *Migration {
- (*migration.Migration)(m).AddUnique((*migration.Unique)(unique))
- return m
-}
-
-// AddForeign adds the column to foreign in m struct
-func (m *Migration) AddForeign(foreign *Foreign) *Migration {
- (*migration.Migration)(m).AddForeign((*migration.Foreign)(foreign))
- return m
-}
-
-// AddIndex adds the column to index in m struct
-func (m *Migration) AddIndex(index *Index) *Migration {
- (*migration.Migration)(m).AddIndex((*migration.Index)(index))
- return m
-}
-
-// RenameColumn allows renaming of columns
-func (m *Migration) RenameColumn(from, to string) *RenameColumn {
- return (*RenameColumn)((*migration.Migration)(m).RenameColumn(from, to))
-}
-
-// GetSQL returns the generated sql depending on ModifyType
-func (m *Migration) GetSQL() (sql string) {
- return (*migration.Migration)(m).GetSQL()
-}
diff --git a/adapter/migration/doc.go b/adapter/migration/doc.go
deleted file mode 100644
index 0c6564d4..00000000
--- a/adapter/migration/doc.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Package migration enables you to generate migrations back and forth. It generates both migrations.
-//
-// //Creates a table
-// m.CreateTable("tablename","InnoDB","utf8");
-//
-// //Alter a table
-// m.AlterTable("tablename")
-//
-// Standard Column Methods
-// * SetDataType
-// * SetNullable
-// * SetDefault
-// * SetUnsigned (use only on integer types unless produces error)
-//
-// //Sets a primary column, multiple calls allowed, standard column methods available
-// m.PriCol("id").SetAuto(true).SetNullable(false).SetDataType("INT(10)").SetUnsigned(true)
-//
-// //UniCol Can be used multiple times, allows standard Column methods. Use same "index" string to add to same index
-// m.UniCol("index","column")
-//
-// //Standard Column Initialisation, can call .Remove() after NewCol("") on alter to remove
-// m.NewCol("name").SetDataType("VARCHAR(255) COLLATE utf8_unicode_ci").SetNullable(false)
-// m.NewCol("value").SetDataType("DOUBLE(8,2)").SetNullable(false)
-//
-// //Rename Columns , only use with Alter table, doesn't works with Create, prefix standard column methods with "Old" to
-// //create a true reversible migration eg: SetOldDataType("DOUBLE(12,3)")
-// m.RenameColumn("from","to")...
-//
-// //Foreign Columns, single columns are only supported, SetOnDelete & SetOnUpdate are available, call appropriately.
-// //Supports standard column methods, automatic reverse.
-// m.ForeignCol("local_col","foreign_col","foreign_table")
-package migration
diff --git a/adapter/migration/migration.go b/adapter/migration/migration.go
deleted file mode 100644
index 57202232..00000000
--- a/adapter/migration/migration.go
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 migration is used for migration
-//
-// The table structure is as follow:
-//
-// CREATE TABLE `migrations` (
-// `id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key',
-// `name` varchar(255) DEFAULT NULL COMMENT 'migration name, unique',
-// `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date migrated or rolled back',
-// `statements` longtext COMMENT 'SQL statements for this migration',
-// `rollback_statements` longtext,
-// `status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back',
-// PRIMARY KEY (`id_migration`)
-// ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-package migration
-
-import (
- "github.com/beego/beego/v2/client/orm/migration"
-)
-
-// const the data format for the bee generate migration datatype
-const (
- DateFormat = "20060102_150405"
- DBDateFormat = "2006-01-02 15:04:05"
-)
-
-// Migrationer is an interface for all Migration struct
-type Migrationer interface {
- Up()
- Down()
- Reset()
- Exec(name, status string) error
- GetCreated() int64
-}
-
-// Migration defines the migrations by either SQL or DDL
-type Migration migration.Migration
-
-// Up implement in the Inheritance struct for upgrade
-func (m *Migration) Up() {
- (*migration.Migration)(m).Up()
-}
-
-// Down implement in the Inheritance struct for down
-func (m *Migration) Down() {
- (*migration.Migration)(m).Down()
-}
-
-// Migrate adds the SQL to the execution list
-func (m *Migration) Migrate(migrationType string) {
- (*migration.Migration)(m).Migrate(migrationType)
-}
-
-// SQL add sql want to execute
-func (m *Migration) SQL(sql string) {
- (*migration.Migration)(m).SQL(sql)
-}
-
-// Reset the sqls
-func (m *Migration) Reset() {
- (*migration.Migration)(m).Reset()
-}
-
-// Exec execute the sql already add in the sql
-func (m *Migration) Exec(name, status string) error {
- return (*migration.Migration)(m).Exec(name, status)
-}
-
-// GetCreated get the unixtime from the Created
-func (m *Migration) GetCreated() int64 {
- return (*migration.Migration)(m).GetCreated()
-}
-
-// Register register the Migration in the map
-func Register(name string, m Migrationer) error {
- return migration.Register(name, m)
-}
-
-// Upgrade upgrade the migration from lasttime
-func Upgrade(lasttime int64) error {
- return migration.Upgrade(lasttime)
-}
-
-// Rollback rollback the migration by the name
-func Rollback(name string) error {
- return migration.Rollback(name)
-}
-
-// Reset reset all migration
-// run all migration's down function
-func Reset() error {
- return migration.Reset()
-}
-
-// Refresh first Reset, then Upgrade
-func Refresh() error {
- return migration.Refresh()
-}
diff --git a/adapter/namespace.go b/adapter/namespace.go
deleted file mode 100644
index 9c3dcbb9..00000000
--- a/adapter/namespace.go
+++ /dev/null
@@ -1,396 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "net/http"
-
- adtContext "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/server/web"
- "github.com/beego/beego/v2/server/web/context"
-)
-
-type namespaceCond func(*adtContext.Context) bool
-
-// LinkNamespace used as link action
-type LinkNamespace func(*Namespace)
-
-// Namespace is store all the info
-type Namespace web.Namespace
-
-// NewNamespace get new Namespace
-func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
- nps := oldToNewLinkNs(params)
- return (*Namespace)(web.NewNamespace(prefix, nps...))
-}
-
-func oldToNewLinkNs(params []LinkNamespace) []web.LinkNamespace {
- nps := make([]web.LinkNamespace, 0, len(params))
- for i := 0; i < len(params); i++ {
- p := params[i]
- nps = append(nps, func(namespace *web.Namespace) {
- p((*Namespace)(namespace))
- })
- }
- return nps
-}
-
-// Cond set condition function
-// if cond return true can run this namespace, else can't
-// usage:
-// ns.Cond(func (ctx *context.Context) bool{
-// if ctx.Input.Domain() == "api.beego.vip" {
-// return true
-// }
-// return false
-// })
-// Cond as the first filter
-func (n *Namespace) Cond(cond namespaceCond) *Namespace {
- (*web.Namespace)(n).Cond(func(context *context.Context) bool {
- return cond((*adtContext.Context)(context))
- })
- return n
-}
-
-// Filter add filter in the Namespace
-// action has before & after
-// FilterFunc
-// usage:
-// Filter("before", func (ctx *context.Context){
-// _, ok := ctx.Input.Session("uid").(int)
-// if !ok && ctx.Request.RequestURI != "/login" {
-// ctx.Redirect(302, "/login")
-// }
-// })
-func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
- nfs := oldToNewFilter(filter)
- (*web.Namespace)(n).Filter(action, nfs...)
- return n
-}
-
-func oldToNewFilter(filter []FilterFunc) []web.FilterFunc {
- nfs := make([]web.FilterFunc, 0, len(filter))
- for i := 0; i < len(filter); i++ {
- f := filter[i]
- nfs = append(nfs, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- }
- return nfs
-}
-
-// Router same as beego.Rourer
-// refer: https://godoc.org/github.com/beego/beego/v2#Router
-func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethods ...string) *Namespace {
- (*web.Namespace)(n).Router(rootpath, c, mappingMethods...)
- return n
-}
-
-// AutoRouter same as beego.AutoRouter
-// refer: https://godoc.org/github.com/beego/beego/v2#AutoRouter
-func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace {
- (*web.Namespace)(n).AutoRouter(c)
- return n
-}
-
-// AutoPrefix same as beego.AutoPrefix
-// refer: https://godoc.org/github.com/beego/beego/v2#AutoPrefix
-func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace {
- (*web.Namespace)(n).AutoPrefix(prefix, c)
- return n
-}
-
-// Get same as beego.Get
-// refer: https://godoc.org/github.com/beego/beego/v2#Get
-func (n *Namespace) Get(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Get(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Post same as beego.Post
-// refer: https://godoc.org/github.com/beego/beego/v2#Post
-func (n *Namespace) Post(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Post(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Delete same as beego.Delete
-// refer: https://godoc.org/github.com/beego/beego/v2#Delete
-func (n *Namespace) Delete(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Delete(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Put same as beego.Put
-// refer: https://godoc.org/github.com/beego/beego/v2#Put
-func (n *Namespace) Put(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Put(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Head same as beego.Head
-// refer: https://godoc.org/github.com/beego/beego/v2#Head
-func (n *Namespace) Head(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Head(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Options same as beego.Options
-// refer: https://godoc.org/github.com/beego/beego/v2#Options
-func (n *Namespace) Options(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Options(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Patch same as beego.Patch
-// refer: https://godoc.org/github.com/beego/beego/v2#Patch
-func (n *Namespace) Patch(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Patch(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Any same as beego.Any
-// refer: https://godoc.org/github.com/beego/beego/v2#Any
-func (n *Namespace) Any(rootpath string, f FilterFunc) *Namespace {
- (*web.Namespace)(n).Any(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return n
-}
-
-// Handler same as beego.Handler
-// refer: https://godoc.org/github.com/beego/beego/v2#Handler
-func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace {
- (*web.Namespace)(n).Handler(rootpath, h)
- return n
-}
-
-// Include add include class
-// refer: https://godoc.org/github.com/beego/beego/v2#Include
-func (n *Namespace) Include(cList ...ControllerInterface) *Namespace {
- nL := oldToNewCtrlIntfs(cList)
- (*web.Namespace)(n).Include(nL...)
- return n
-}
-
-// Namespace add nest Namespace
-// usage:
-// ns := beego.NewNamespace(“/v1”).
-// Namespace(
-// beego.NewNamespace("/shop").
-// Get("/:id", func(ctx *context.Context) {
-// ctx.Output.Body([]byte("shopinfo"))
-// }),
-// beego.NewNamespace("/order").
-// Get("/:id", func(ctx *context.Context) {
-// ctx.Output.Body([]byte("orderinfo"))
-// }),
-// beego.NewNamespace("/crm").
-// Get("/:id", func(ctx *context.Context) {
-// ctx.Output.Body([]byte("crminfo"))
-// }),
-// )
-func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
- nns := oldToNewNs(ns)
- (*web.Namespace)(n).Namespace(nns...)
- return n
-}
-
-func oldToNewNs(ns []*Namespace) []*web.Namespace {
- nns := make([]*web.Namespace, 0, len(ns))
- for _, n := range ns {
- nns = append(nns, (*web.Namespace)(n))
- }
- return nns
-}
-
-// AddNamespace register Namespace into beego.Handler
-// support multi Namespace
-func AddNamespace(nl ...*Namespace) {
- nnl := oldToNewNs(nl)
- web.AddNamespace(nnl...)
-}
-
-// NSCond is Namespace Condition
-func NSCond(cond namespaceCond) LinkNamespace {
- wc := web.NSCond(func(b *context.Context) bool {
- return cond((*adtContext.Context)(b))
- })
- return func(namespace *Namespace) {
- wc((*web.Namespace)(namespace))
- }
-}
-
-// NSBefore Namespace BeforeRouter filter
-func NSBefore(filterList ...FilterFunc) LinkNamespace {
- nfs := oldToNewFilter(filterList)
- wf := web.NSBefore(nfs...)
- return func(namespace *Namespace) {
- wf((*web.Namespace)(namespace))
- }
-}
-
-// NSAfter add Namespace FinishRouter filter
-func NSAfter(filterList ...FilterFunc) LinkNamespace {
- nfs := oldToNewFilter(filterList)
- wf := web.NSAfter(nfs...)
- return func(namespace *Namespace) {
- wf((*web.Namespace)(namespace))
- }
-}
-
-// NSInclude Namespace Include ControllerInterface
-func NSInclude(cList ...ControllerInterface) LinkNamespace {
- nfs := oldToNewCtrlIntfs(cList)
- wi := web.NSInclude(nfs...)
- return func(namespace *Namespace) {
- wi((*web.Namespace)(namespace))
- }
-}
-
-// NSRouter call Namespace Router
-func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace {
- wn := web.NSRouter(rootpath, c, mappingMethods...)
- return func(namespace *Namespace) {
- wn((*web.Namespace)(namespace))
- }
-}
-
-// NSGet call Namespace Get
-func NSGet(rootpath string, f FilterFunc) LinkNamespace {
- ln := web.NSGet(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- ln((*web.Namespace)(ns))
- }
-}
-
-// NSPost call Namespace Post
-func NSPost(rootpath string, f FilterFunc) LinkNamespace {
- wp := web.NSPost(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wp((*web.Namespace)(ns))
- }
-}
-
-// NSHead call Namespace Head
-func NSHead(rootpath string, f FilterFunc) LinkNamespace {
- wb := web.NSHead(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wb((*web.Namespace)(ns))
- }
-}
-
-// NSPut call Namespace Put
-func NSPut(rootpath string, f FilterFunc) LinkNamespace {
- wn := web.NSPut(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSDelete call Namespace Delete
-func NSDelete(rootpath string, f FilterFunc) LinkNamespace {
- wn := web.NSDelete(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSAny call Namespace Any
-func NSAny(rootpath string, f FilterFunc) LinkNamespace {
- wn := web.NSAny(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSOptions call Namespace Options
-func NSOptions(rootpath string, f FilterFunc) LinkNamespace {
- wo := web.NSOptions(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wo((*web.Namespace)(ns))
- }
-}
-
-// NSPatch call Namespace Patch
-func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
- wn := web.NSPatch(rootpath, func(ctx *context.Context) {
- f((*adtContext.Context)(ctx))
- })
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSAutoRouter call Namespace AutoRouter
-func NSAutoRouter(c ControllerInterface) LinkNamespace {
- wn := web.NSAutoRouter(c)
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSAutoPrefix call Namespace AutoPrefix
-func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace {
- wn := web.NSAutoPrefix(prefix, c)
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSNamespace add sub Namespace
-func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace {
- nps := oldToNewLinkNs(params)
- wn := web.NSNamespace(prefix, nps...)
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
-
-// NSHandler add handler
-func NSHandler(rootpath string, h http.Handler) LinkNamespace {
- wn := web.NSHandler(rootpath, h)
- return func(ns *Namespace) {
- wn((*web.Namespace)(ns))
- }
-}
diff --git a/adapter/orm/cmd.go b/adapter/orm/cmd.go
deleted file mode 100644
index d8399c90..00000000
--- a/adapter/orm/cmd.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// RunCommand listen for orm command and then run it if command arguments passed.
-func RunCommand() {
- orm.RunCommand()
-}
-
-func RunSyncdb(name string, force bool, verbose bool) error {
- return orm.RunSyncdb(name, force, verbose)
-}
diff --git a/adapter/orm/db.go b/adapter/orm/db.go
deleted file mode 100644
index c1d1fe92..00000000
--- a/adapter/orm/db.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// ErrMissPK missing pk error
-var ErrMissPK = orm.ErrMissPK
diff --git a/adapter/orm/db_alias.go b/adapter/orm/db_alias.go
deleted file mode 100644
index a196ca23..00000000
--- a/adapter/orm/db_alias.go
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 (
- "context"
- "database/sql"
- "time"
-
- "github.com/beego/beego/v2/client/orm"
-)
-
-// DriverType database driver constant int.
-type DriverType orm.DriverType
-
-// Enum the Database driver
-const (
- DRMySQL = DriverType(orm.DRMySQL)
- DRSqlite = DriverType(orm.DRSqlite) // sqlite
- DROracle = DriverType(orm.DROracle) // oracle
- DRPostgres = DriverType(orm.DRPostgres) // pgsql
- DRTiDB = DriverType(orm.DRTiDB) // TiDB
-)
-
-type DB orm.DB
-
-func (d *DB) Begin() (*sql.Tx, error) {
- return (*orm.DB)(d).Begin()
-}
-
-func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) {
- return (*orm.DB)(d).BeginTx(ctx, opts)
-}
-
-func (d *DB) Prepare(query string) (*sql.Stmt, error) {
- return (*orm.DB)(d).Prepare(query)
-}
-
-func (d *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
- return (*orm.DB)(d).PrepareContext(ctx, query)
-}
-
-func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
- return (*orm.DB)(d).Exec(query, args...)
-}
-
-func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
- return (*orm.DB)(d).ExecContext(ctx, query, args...)
-}
-
-func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
- return (*orm.DB)(d).Query(query, args...)
-}
-
-func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
- return (*orm.DB)(d).QueryContext(ctx, query, args...)
-}
-
-func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row {
- return (*orm.DB)(d).QueryRow(query, args...)
-}
-
-func (d *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
- return (*orm.DB)(d).QueryRowContext(ctx, query, args...)
-}
-
-// AddAliasWthDB add a aliasName for the drivename
-func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error {
- return orm.AddAliasWthDB(aliasName, driverName, db)
-}
-
-// RegisterDataBase Setting the database connect params. Use the database driver self dataSource args.
-func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error {
- opts := make([]orm.DBOption, 0, 2)
- if len(params) > 0 {
- opts = append(opts, orm.MaxIdleConnections(params[0]))
- }
-
- if len(params) > 1 {
- opts = append(opts, orm.MaxOpenConnections(params[1]))
- }
- return orm.RegisterDataBase(aliasName, driverName, dataSource, opts...)
-}
-
-// RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
-func RegisterDriver(driverName string, typ DriverType) error {
- return orm.RegisterDriver(driverName, orm.DriverType(typ))
-}
-
-// SetDataBaseTZ Change the database default used timezone
-func SetDataBaseTZ(aliasName string, tz *time.Location) error {
- return orm.SetDataBaseTZ(aliasName, tz)
-}
-
-// SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name
-func SetMaxIdleConns(aliasName string, maxIdleConns int) {
- orm.SetMaxIdleConns(aliasName, maxIdleConns)
-}
-
-// SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name
-func SetMaxOpenConns(aliasName string, maxOpenConns int) {
- orm.SetMaxOpenConns(aliasName, maxOpenConns)
-}
-
-// GetDB Get *sql.DB from registered database by db alias name.
-// Use "default" as alias name if you not set.
-func GetDB(aliasNames ...string) (*sql.DB, error) {
- return orm.GetDB(aliasNames...)
-}
diff --git a/adapter/orm/models.go b/adapter/orm/models.go
deleted file mode 100644
index ee6b9194..00000000
--- a/adapter/orm/models.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// ResetModelCache Clean model cache. Then you can re-RegisterModel.
-// Common use this api for test case.
-func ResetModelCache() {
- orm.ResetModelCache()
-}
diff --git a/adapter/orm/models_boot.go b/adapter/orm/models_boot.go
deleted file mode 100644
index 678b86e6..00000000
--- a/adapter/orm/models_boot.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// RegisterModel register models
-func RegisterModel(models ...interface{}) {
- orm.RegisterModel(models...)
-}
-
-// RegisterModelWithPrefix register models with a prefix
-func RegisterModelWithPrefix(prefix string, models ...interface{}) {
- orm.RegisterModelWithPrefix(prefix, models...)
-}
-
-// RegisterModelWithSuffix register models with a suffix
-func RegisterModelWithSuffix(suffix string, models ...interface{}) {
- orm.RegisterModelWithSuffix(suffix, models...)
-}
-
-// BootStrap bootstrap models.
-// make all model parsed and can not add more models
-func BootStrap() {
- orm.BootStrap()
-}
diff --git a/adapter/orm/models_boot_test.go b/adapter/orm/models_boot_test.go
deleted file mode 100644
index 5471885b..00000000
--- a/adapter/orm/models_boot_test.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2020 beego
-//
-// 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 (
- "testing"
-)
-
-type User struct {
- Id int
-}
-
-type Seller struct {
- Id int
-}
-
-func TestRegisterModelWithPrefix(t *testing.T) {
- RegisterModelWithPrefix("test", &User{}, &Seller{})
-}
diff --git a/adapter/orm/orm.go b/adapter/orm/orm.go
deleted file mode 100644
index 2b2b29e0..00000000
--- a/adapter/orm/orm.go
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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.
-
-//go:build go1.8
-// +build go1.8
-
-// Package orm provide ORM for MySQL/PostgreSQL/sqlite
-// Simple Usage
-//
-// package main
-//
-// import (
-// "fmt"
-// "github.com/beego/beego/v2/client/orm"
-// _ "github.com/go-sql-driver/mysql" // import your used driver
-// )
-//
-// // Model Struct
-// type User struct {
-// Id int `orm:"auto"`
-// Name string `orm:"size(100)"`
-// }
-//
-// func init() {
-// orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30)
-// }
-//
-// func main() {
-// o := orm.NewOrm()
-// user := User{Name: "slene"}
-// // insert
-// id, err := o.Insert(&user)
-// // update
-// user.Name = "astaxie"
-// num, err := o.Update(&user)
-// // read one
-// u := User{Id: user.Id}
-// err = o.Read(&u)
-// // delete
-// num, err = o.Delete(&u)
-// }
-//
-package orm
-
-import (
- "context"
- "database/sql"
- "errors"
-
- "github.com/beego/beego/v2/client/orm"
- "github.com/beego/beego/v2/client/orm/hints"
- "github.com/beego/beego/v2/core/utils"
-)
-
-// DebugQueries define the debug
-const (
- DebugQueries = iota
-)
-
-// Define common vars
-var (
- Debug = orm.Debug
- DebugLog = orm.DebugLog
- DefaultRowsLimit = orm.DefaultRowsLimit
- DefaultRelsDepth = orm.DefaultRelsDepth
- DefaultTimeLoc = orm.DefaultTimeLoc
- ErrTxHasBegan = errors.New(" transaction already begin")
- ErrTxDone = errors.New(" transaction not begin")
- ErrMultiRows = errors.New(" return multi rows")
- ErrNoRows = errors.New(" no row found")
- ErrStmtClosed = errors.New(" stmt already closed")
- ErrArgs = errors.New(" args error may be empty")
- ErrNotImplement = errors.New("have not implement")
-)
-
-type ormer struct {
- delegate orm.Ormer
- txDelegate orm.TxOrmer
- isTx bool
-}
-
-var _ Ormer = new(ormer)
-
-// Read read data to model
-func (o *ormer) Read(md interface{}, cols ...string) error {
- if o.isTx {
- return o.txDelegate.Read(md, cols...)
- }
- return o.delegate.Read(md, cols...)
-}
-
-// ReadForUpdate read data to model, like Read(), but use "SELECT FOR UPDATE" form
-func (o *ormer) ReadForUpdate(md interface{}, cols ...string) error {
- if o.isTx {
- return o.txDelegate.ReadForUpdate(md, cols...)
- }
- return o.delegate.ReadForUpdate(md, cols...)
-}
-
-// ReadOrCreate Try to read a row from the database, or insert one if it doesn't exist
-func (o *ormer) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) {
- if o.isTx {
- return o.txDelegate.ReadOrCreate(md, col1, cols...)
- }
- return o.delegate.ReadOrCreate(md, col1, cols...)
-}
-
-// Insert will insert model data to database
-func (o *ormer) Insert(md interface{}) (int64, error) {
- if o.isTx {
- return o.txDelegate.Insert(md)
- }
- return o.delegate.Insert(md)
-}
-
-// InsertMulti will insert some models to database
-func (o *ormer) InsertMulti(bulk int, mds interface{}) (int64, error) {
- if o.isTx {
- return o.txDelegate.InsertMulti(bulk, mds)
- }
- return o.delegate.InsertMulti(bulk, mds)
-}
-
-// InsertOrUpdate data to database
-func (o *ormer) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error) {
- if o.isTx {
- return o.txDelegate.InsertOrUpdate(md, colConflitAndArgs...)
- }
- return o.delegate.InsertOrUpdate(md, colConflitAndArgs...)
-}
-
-// Update will update model to database.
-// cols set the columns those want to update.
-func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
- if o.isTx {
- return o.txDelegate.Update(md, cols...)
- }
- return o.delegate.Update(md, cols...)
-}
-
-// Delete delete model in database
-// cols shows the delete conditions values read from. default is pk
-func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
- if o.isTx {
- return o.txDelegate.Delete(md, cols...)
- }
- return o.delegate.Delete(md, cols...)
-}
-
-// QueryM2M create a models to models queryer
-func (o *ormer) QueryM2M(md interface{}, name string) QueryM2Mer {
- if o.isTx {
- return o.txDelegate.QueryM2M(md, name)
- }
- return o.delegate.QueryM2M(md, name)
-}
-
-// LoadRelated load related models to md model.
-// args are limit, offset int and order string.
-//
-// example:
-// orm.LoadRelated(post,"Tags")
-// for _,tag := range post.Tags{...}
-//
-// make sure the relation is defined in model struct tags.
-func (o *ormer) LoadRelated(md interface{}, name string, args ...interface{}) (int64, error) {
- kvs := make([]utils.KV, 0, 4)
- for i, arg := range args {
- switch i {
- case 0:
- if v, ok := arg.(bool); ok {
- if v {
- kvs = append(kvs, hints.DefaultRelDepth())
- }
- } else if v, ok := arg.(int); ok {
- kvs = append(kvs, hints.RelDepth(v))
- }
- case 1:
- kvs = append(kvs, hints.Limit(orm.ToInt64(arg)))
- case 2:
- kvs = append(kvs, hints.Offset(orm.ToInt64(arg)))
- case 3:
- kvs = append(kvs, hints.Offset(orm.ToInt64(arg)))
- }
- }
- if o.isTx {
- return o.txDelegate.LoadRelated(md, name, kvs...)
- }
- return o.delegate.LoadRelated(md, name, kvs...)
-}
-
-// QueryTable return a QuerySeter for table operations.
-// table name can be string or struct.
-// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
-func (o *ormer) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
- if o.isTx {
- return o.txDelegate.QueryTable(ptrStructOrTableName)
- }
- return o.delegate.QueryTable(ptrStructOrTableName)
-}
-
-// Using switch to another registered database driver by given name.
-func (o *ormer) Using(name string) error {
- if o.isTx {
- return ErrTxHasBegan
- }
- o.delegate = orm.NewOrmUsingDB(name)
- return nil
-}
-
-// Begin will begin transaction
-func (o *ormer) Begin() error {
- if o.isTx {
- return ErrTxHasBegan
- }
- return o.BeginTx(context.Background(), nil)
-}
-
-func (o *ormer) BeginTx(ctx context.Context, opts *sql.TxOptions) error {
- if o.isTx {
- return ErrTxHasBegan
- }
- txOrmer, err := o.delegate.BeginWithCtxAndOpts(ctx, opts)
- if err != nil {
- return err
- }
- o.txDelegate = txOrmer
- o.isTx = true
- return nil
-}
-
-// Commit will commit transaction
-func (o *ormer) Commit() error {
- if !o.isTx {
- return ErrTxDone
- }
- err := o.txDelegate.Commit()
- if err == nil {
- o.isTx = false
- o.txDelegate = nil
- } else if err == sql.ErrTxDone {
- return ErrTxDone
- }
- return err
-}
-
-// Rollback will rollback transaction
-func (o *ormer) Rollback() error {
- if !o.isTx {
- return ErrTxDone
- }
- err := o.txDelegate.Rollback()
- if err == nil {
- o.isTx = false
- o.txDelegate = nil
- } else if err == sql.ErrTxDone {
- return ErrTxDone
- }
- return err
-}
-
-// Raw return a raw query seter for raw sql string.
-func (o *ormer) Raw(query string, args ...interface{}) RawSeter {
- if o.isTx {
- return o.txDelegate.Raw(query, args...)
- }
- return o.delegate.Raw(query, args...)
-}
-
-// Driver return current using database Driver
-func (o *ormer) Driver() Driver {
- if o.isTx {
- return o.txDelegate.Driver()
- }
- return o.delegate.Driver()
-}
-
-// DBStats return sql.DBStats for current database
-func (o *ormer) DBStats() *sql.DBStats {
- if o.isTx {
- return o.txDelegate.DBStats()
- }
- return o.delegate.DBStats()
-}
-
-// NewOrm create new orm
-func NewOrm() Ormer {
- o := orm.NewOrm()
- return &ormer{
- delegate: o,
- }
-}
-
-// NewOrmWithDB create a new ormer object with specify *sql.DB for query
-func NewOrmWithDB(driverName, aliasName string, db *sql.DB) (Ormer, error) {
- o, err := orm.NewOrmWithDB(driverName, aliasName, db)
- if err != nil {
- return nil, err
- }
- return &ormer{
- delegate: o,
- }, nil
-}
diff --git a/adapter/orm/orm_conds.go b/adapter/orm/orm_conds.go
deleted file mode 100644
index 4a713fcd..00000000
--- a/adapter/orm/orm_conds.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// ExprSep define the expression separation
-const (
- ExprSep = "__"
-)
-
-// Condition struct.
-// work for WHERE conditions.
-type Condition orm.Condition
-
-// NewCondition return new condition struct
-func NewCondition() *Condition {
- return (*Condition)(orm.NewCondition())
-}
-
-// Raw add raw sql to condition
-func (c Condition) Raw(expr string, sql string) *Condition {
- return (*Condition)((orm.Condition)(c).Raw(expr, sql))
-}
-
-// And add expression to condition
-func (c Condition) And(expr string, args ...interface{}) *Condition {
- return (*Condition)((orm.Condition)(c).And(expr, args...))
-}
-
-// AndNot add NOT expression to condition
-func (c Condition) AndNot(expr string, args ...interface{}) *Condition {
- return (*Condition)((orm.Condition)(c).AndNot(expr, args...))
-}
-
-// AndCond combine a condition to current condition
-func (c *Condition) AndCond(cond *Condition) *Condition {
- return (*Condition)((*orm.Condition)(c).AndCond((*orm.Condition)(cond)))
-}
-
-// AndNotCond combine an AND NOT condition to current condition
-func (c *Condition) AndNotCond(cond *Condition) *Condition {
- return (*Condition)((*orm.Condition)(c).AndNotCond((*orm.Condition)(cond)))
-}
-
-// Or add OR expression to condition
-func (c Condition) Or(expr string, args ...interface{}) *Condition {
- return (*Condition)((orm.Condition)(c).Or(expr, args...))
-}
-
-// OrNot add OR NOT expression to condition
-func (c Condition) OrNot(expr string, args ...interface{}) *Condition {
- return (*Condition)((orm.Condition)(c).OrNot(expr, args...))
-}
-
-// OrCond combine an OR condition to current condition
-func (c *Condition) OrCond(cond *Condition) *Condition {
- return (*Condition)((*orm.Condition)(c).OrCond((*orm.Condition)(cond)))
-}
-
-// OrNotCond combine an OR NOT condition to current condition
-func (c *Condition) OrNotCond(cond *Condition) *Condition {
- return (*Condition)((*orm.Condition)(c).OrNotCond((*orm.Condition)(cond)))
-}
-
-// IsEmpty check the condition arguments are empty or not.
-func (c *Condition) IsEmpty() bool {
- return (*orm.Condition)(c).IsEmpty()
-}
diff --git a/adapter/orm/orm_queryset.go b/adapter/orm/orm_queryset.go
deleted file mode 100644
index b1f4c165..00000000
--- a/adapter/orm/orm_queryset.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// define Col operations
-const (
- ColAdd = orm.ColAdd
- ColMinus = orm.ColMinus
- ColMultiply = orm.ColMultiply
- ColExcept = orm.ColExcept
- ColBitAnd = orm.ColBitAnd
- ColBitRShift = orm.ColBitRShift
- ColBitLShift = orm.ColBitLShift
- ColBitXOR = orm.ColBitXOR
- ColBitOr = orm.ColBitOr
-)
diff --git a/adapter/orm/qb.go b/adapter/orm/qb.go
deleted file mode 100644
index 57c8d62a..00000000
--- a/adapter/orm/qb.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// QueryBuilder is the Query builder interface
-type QueryBuilder orm.QueryBuilder
-
-// NewQueryBuilder return the QueryBuilder
-func NewQueryBuilder(driver string) (qb QueryBuilder, err error) {
- return orm.NewQueryBuilder(driver)
-}
diff --git a/adapter/orm/qb_mysql.go b/adapter/orm/qb_mysql.go
deleted file mode 100644
index 10b38ea9..00000000
--- a/adapter/orm/qb_mysql.go
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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"
-)
-
-// CommaSpace is the separation
-const CommaSpace = orm.CommaSpace
-
-// MySQLQueryBuilder is the SQL build
-type MySQLQueryBuilder orm.MySQLQueryBuilder
-
-// Select will join the fields
-func (qb *MySQLQueryBuilder) Select(fields ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Select(fields...)
-}
-
-// ForUpdate add the FOR UPDATE clause
-func (qb *MySQLQueryBuilder) ForUpdate() QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).ForUpdate()
-}
-
-// From join the tables
-func (qb *MySQLQueryBuilder) From(tables ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).From(tables...)
-}
-
-// InnerJoin INNER JOIN the table
-func (qb *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).InnerJoin(table)
-}
-
-// LeftJoin LEFT JOIN the table
-func (qb *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).LeftJoin(table)
-}
-
-// RightJoin RIGHT JOIN the table
-func (qb *MySQLQueryBuilder) RightJoin(table string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).RightJoin(table)
-}
-
-// On join with on cond
-func (qb *MySQLQueryBuilder) On(cond string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).On(cond)
-}
-
-// Where join the Where cond
-func (qb *MySQLQueryBuilder) Where(cond string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Where(cond)
-}
-
-// And join the and cond
-func (qb *MySQLQueryBuilder) And(cond string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).And(cond)
-}
-
-// Or join the or cond
-func (qb *MySQLQueryBuilder) Or(cond string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Or(cond)
-}
-
-// In join the IN (vals)
-func (qb *MySQLQueryBuilder) In(vals ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).In(vals...)
-}
-
-// OrderBy join the Order by fields
-func (qb *MySQLQueryBuilder) OrderBy(fields ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).OrderBy(fields...)
-}
-
-// Asc join the asc
-func (qb *MySQLQueryBuilder) Asc() QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Asc()
-}
-
-// Desc join the desc
-func (qb *MySQLQueryBuilder) Desc() QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Desc()
-}
-
-// Limit join the limit num
-func (qb *MySQLQueryBuilder) Limit(limit int) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Limit(limit)
-}
-
-// Offset join the offset num
-func (qb *MySQLQueryBuilder) Offset(offset int) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Offset(offset)
-}
-
-// GroupBy join the Group by fields
-func (qb *MySQLQueryBuilder) GroupBy(fields ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).GroupBy(fields...)
-}
-
-// Having join the Having cond
-func (qb *MySQLQueryBuilder) Having(cond string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Having(cond)
-}
-
-// Update join the update table
-func (qb *MySQLQueryBuilder) Update(tables ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Update(tables...)
-}
-
-// Set join the set kv
-func (qb *MySQLQueryBuilder) Set(kv ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Set(kv...)
-}
-
-// Delete join the Delete tables
-func (qb *MySQLQueryBuilder) Delete(tables ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Delete(tables...)
-}
-
-// InsertInto join the insert SQL
-func (qb *MySQLQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).InsertInto(table, fields...)
-}
-
-// Values join the Values(vals)
-func (qb *MySQLQueryBuilder) Values(vals ...string) QueryBuilder {
- return (*orm.MySQLQueryBuilder)(qb).Values(vals...)
-}
-
-// Subquery join the sub as alias
-func (qb *MySQLQueryBuilder) Subquery(sub string, alias string) string {
- return (*orm.MySQLQueryBuilder)(qb).Subquery(sub, alias)
-}
-
-// String join all Tokens
-func (qb *MySQLQueryBuilder) String() string {
- return (*orm.MySQLQueryBuilder)(qb).String()
-}
diff --git a/adapter/orm/qb_tidb.go b/adapter/orm/qb_tidb.go
deleted file mode 100644
index d3c94e0f..00000000
--- a/adapter/orm/qb_tidb.go
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright 2015 TiDB Author. All Rights Reserved.
-//
-// 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"
-)
-
-// TiDBQueryBuilder is the SQL build
-type TiDBQueryBuilder orm.TiDBQueryBuilder
-
-// Select will join the fields
-func (qb *TiDBQueryBuilder) Select(fields ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Select(fields...)
-}
-
-// ForUpdate add the FOR UPDATE clause
-func (qb *TiDBQueryBuilder) ForUpdate() QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).ForUpdate()
-}
-
-// From join the tables
-func (qb *TiDBQueryBuilder) From(tables ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).From(tables...)
-}
-
-// InnerJoin INNER JOIN the table
-func (qb *TiDBQueryBuilder) InnerJoin(table string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).InnerJoin(table)
-}
-
-// LeftJoin LEFT JOIN the table
-func (qb *TiDBQueryBuilder) LeftJoin(table string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).LeftJoin(table)
-}
-
-// RightJoin RIGHT JOIN the table
-func (qb *TiDBQueryBuilder) RightJoin(table string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).RightJoin(table)
-}
-
-// On join with on cond
-func (qb *TiDBQueryBuilder) On(cond string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).On(cond)
-}
-
-// Where join the Where cond
-func (qb *TiDBQueryBuilder) Where(cond string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Where(cond)
-}
-
-// And join the and cond
-func (qb *TiDBQueryBuilder) And(cond string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).And(cond)
-}
-
-// Or join the or cond
-func (qb *TiDBQueryBuilder) Or(cond string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Or(cond)
-}
-
-// In join the IN (vals)
-func (qb *TiDBQueryBuilder) In(vals ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).In(vals...)
-}
-
-// OrderBy join the Order by fields
-func (qb *TiDBQueryBuilder) OrderBy(fields ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).OrderBy(fields...)
-}
-
-// Asc join the asc
-func (qb *TiDBQueryBuilder) Asc() QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Asc()
-}
-
-// Desc join the desc
-func (qb *TiDBQueryBuilder) Desc() QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Desc()
-}
-
-// Limit join the limit num
-func (qb *TiDBQueryBuilder) Limit(limit int) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Limit(limit)
-}
-
-// Offset join the offset num
-func (qb *TiDBQueryBuilder) Offset(offset int) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Offset(offset)
-}
-
-// GroupBy join the Group by fields
-func (qb *TiDBQueryBuilder) GroupBy(fields ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).GroupBy(fields...)
-}
-
-// Having join the Having cond
-func (qb *TiDBQueryBuilder) Having(cond string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Having(cond)
-}
-
-// Update join the update table
-func (qb *TiDBQueryBuilder) Update(tables ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Update(tables...)
-}
-
-// Set join the set kv
-func (qb *TiDBQueryBuilder) Set(kv ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Set(kv...)
-}
-
-// Delete join the Delete tables
-func (qb *TiDBQueryBuilder) Delete(tables ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Delete(tables...)
-}
-
-// InsertInto join the insert SQL
-func (qb *TiDBQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).InsertInto(table, fields...)
-}
-
-// Values join the Values(vals)
-func (qb *TiDBQueryBuilder) Values(vals ...string) QueryBuilder {
- return (*orm.TiDBQueryBuilder)(qb).Values(vals...)
-}
-
-// Subquery join the sub as alias
-func (qb *TiDBQueryBuilder) Subquery(sub string, alias string) string {
- return (*orm.TiDBQueryBuilder)(qb).Subquery(sub, alias)
-}
-
-// String join all Tokens
-func (qb *TiDBQueryBuilder) String() string {
- return (*orm.TiDBQueryBuilder)(qb).String()
-}
diff --git a/adapter/orm/types.go b/adapter/orm/types.go
deleted file mode 100644
index ecc4d6f4..00000000
--- a/adapter/orm/types.go
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 (
- "context"
- "database/sql"
-
- "github.com/beego/beego/v2/client/orm"
-)
-
-// Params stores the Params
-type Params orm.Params
-
-// ParamsList stores paramslist
-type ParamsList orm.ParamsList
-
-// Driver define database driver
-type Driver orm.Driver
-
-// Fielder define field info
-type Fielder orm.Fielder
-
-// Ormer define the orm interface
-type Ormer interface {
- // Read read data to model
- // for example:
- // this will find User by Id field
- // u = &User{Id: user.Id}
- // err = Ormer.Read(u)
- // this will find User by UserName field
- // u = &User{UserName: "astaxie", Password: "pass"}
- // err = Ormer.Read(u, "UserName")
- Read(md interface{}, cols ...string) error
- // ReadForUpdate Like Read(), but with "FOR UPDATE" clause, useful in transaction.
- // Some databases are not support this feature.
- ReadForUpdate(md interface{}, cols ...string) error
- // ReadOrCreate Try to read a row from the database, or insert one if it doesn't exist
- ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error)
- // Insert will insert model data to database
- // for example:
- // user := new(User)
- // id, err = Ormer.Insert(user)
- // user must be a pointer and Insert will set user's pk field
- Insert(interface{}) (int64, error)
- // InsertOrUpdate(model,"colu=colu+value") or mysql:InsertOrUpdate(model)
- // if colu type is integer : can use(+-*/), string : convert(colu,"value")
- // postgres: InsertOrUpdate(model,"conflictColumnName") or InsertOrUpdate(model,"conflictColumnName","colu=colu+value")
- // if colu type is integer : can use(+-*/), string : colu || "value"
- InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error)
- // InsertMulti insert some models to database
- InsertMulti(bulk int, mds interface{}) (int64, error)
- // Update update model to database.
- // cols set the columns those want to update.
- // find model by Id(pk) field and update columns specified by fields, if cols is null then update all columns
- // for example:
- // user := User{Id: 2}
- // user.Langs = append(user.Langs, "zh-CN", "en-US")
- // user.Extra.Name = "beego"
- // user.Extra.Data = "orm"
- // num, err = Ormer.Update(&user, "Langs", "Extra")
- Update(md interface{}, cols ...string) (int64, error)
- // Delete delete model in database
- Delete(md interface{}, cols ...string) (int64, error)
- // LoadRelated load related models to md model.
- // args are limit, offset int and order string.
- //
- // example:
- // Ormer.LoadRelated(post,"Tags")
- // for _,tag := range post.Tags{...}
- // args[0] bool true useDefaultRelsDepth ; false depth 0
- // args[0] int loadRelationDepth
- // args[1] int limit default limit 1000
- // args[2] int offset default offset 0
- // args[3] string order for example : "-Id"
- // make sure the relation is defined in model struct tags.
- LoadRelated(md interface{}, name string, args ...interface{}) (int64, error)
- // QueryM2M create a models to models queryer
- // for example:
- // post := Post{Id: 4}
- // m2m := Ormer.QueryM2M(&post, "Tags")
- QueryM2M(md interface{}, name string) QueryM2Mer
- // QueryTable return a QuerySeter for table operations.
- // table name can be string or struct.
- // e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
- QueryTable(ptrStructOrTableName interface{}) QuerySeter
- // switch to another registered database driver by given name.
- Using(name string) error
- // Begin begin transaction
- // for example:
- // o := NewOrm()
- // err := o.Begin()
- // ...
- // err = o.Rollback()
- Begin() error
- // BeginTx begin transaction with provided context and option
- // the provided context is used until the transaction is committed or rolled back.
- // if the context is canceled, the transaction will be rolled back.
- // the provided TxOptions is optional and may be nil if defaults should be used.
- // if a non-default isolation level is used that the driver doesn't support, an error will be returned.
- // for example:
- // o := NewOrm()
- // err := o.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelRepeatableRead})
- // ...
- // err = o.Rollback()
- BeginTx(ctx context.Context, opts *sql.TxOptions) error
- // Commit commit transaction
- Commit() error
- // Rollback rollback transaction
- Rollback() error
- // Raw return a raw query seter for raw sql string.
- // for example:
- // ormer.Raw("UPDATE `user` SET `user_name` = ? WHERE `user_name` = ?", "slene", "testing").Exec()
- // // update user testing's name to slene
- Raw(query string, args ...interface{}) RawSeter
- Driver() Driver
- DBStats() *sql.DBStats
-}
-
-// Inserter insert prepared statement
-type Inserter orm.Inserter
-
-// QuerySeter query seter
-type QuerySeter orm.QuerySeter
-
-// QueryM2Mer model to model query struct
-// all operations are on the m2m table only, will not affect the origin model table
-type QueryM2Mer orm.QueryM2Mer
-
-// RawPreparer raw query statement
-type RawPreparer orm.RawPreparer
-
-// RawSeter raw query seter
-// create From Ormer.Raw
-// for example:
-// sql := fmt.Sprintf("SELECT %sid%s,%sname%s FROM %suser%s WHERE id = ?",Q,Q,Q,Q,Q,Q)
-// rs := Ormer.Raw(sql, 1)
-type RawSeter orm.RawSeter
diff --git a/adapter/orm/utils.go b/adapter/orm/utils.go
deleted file mode 100644
index a88836c3..00000000
--- a/adapter/orm/utils.go
+++ /dev/null
@@ -1,286 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 (
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "github.com/beego/beego/v2/client/orm"
-)
-
-type fn func(string) string
-
-var (
- nameStrategyMap = map[string]fn{
- defaultNameStrategy: snakeString,
- SnakeAcronymNameStrategy: snakeStringWithAcronym,
- }
- defaultNameStrategy = "snakeString"
- SnakeAcronymNameStrategy = "snakeStringWithAcronym"
- nameStrategy = defaultNameStrategy
-)
-
-// StrTo is the target string
-type StrTo orm.StrTo
-
-// Set string
-func (f *StrTo) Set(v string) {
- (*orm.StrTo)(f).Set(v)
-}
-
-// Clear string
-func (f *StrTo) Clear() {
- (*orm.StrTo)(f).Clear()
-}
-
-// Exist check string exist
-func (f StrTo) Exist() bool {
- return orm.StrTo(f).Exist()
-}
-
-// Bool string to bool
-func (f StrTo) Bool() (bool, error) {
- return orm.StrTo(f).Bool()
-}
-
-// Float32 string to float32
-func (f StrTo) Float32() (float32, error) {
- return orm.StrTo(f).Float32()
-}
-
-// Float64 string to float64
-func (f StrTo) Float64() (float64, error) {
- return orm.StrTo(f).Float64()
-}
-
-// Int string to int
-func (f StrTo) Int() (int, error) {
- return orm.StrTo(f).Int()
-}
-
-// Int8 string to int8
-func (f StrTo) Int8() (int8, error) {
- return orm.StrTo(f).Int8()
-}
-
-// Int16 string to int16
-func (f StrTo) Int16() (int16, error) {
- return orm.StrTo(f).Int16()
-}
-
-// Int32 string to int32
-func (f StrTo) Int32() (int32, error) {
- return orm.StrTo(f).Int32()
-}
-
-// Int64 string to int64
-func (f StrTo) Int64() (int64, error) {
- return orm.StrTo(f).Int64()
-}
-
-// Uint string to uint
-func (f StrTo) Uint() (uint, error) {
- return orm.StrTo(f).Uint()
-}
-
-// Uint8 string to uint8
-func (f StrTo) Uint8() (uint8, error) {
- return orm.StrTo(f).Uint8()
-}
-
-// Uint16 string to uint16
-func (f StrTo) Uint16() (uint16, error) {
- return orm.StrTo(f).Uint16()
-}
-
-// Uint32 string to uint32
-func (f StrTo) Uint32() (uint32, error) {
- return orm.StrTo(f).Uint32()
-}
-
-// Uint64 string to uint64
-func (f StrTo) Uint64() (uint64, error) {
- return orm.StrTo(f).Uint64()
-}
-
-// String string to string
-func (f StrTo) String() string {
- return orm.StrTo(f).String()
-}
-
-// ToStr interface to string
-func ToStr(value interface{}, args ...int) (s string) {
- switch v := value.(type) {
- case bool:
- s = strconv.FormatBool(v)
- case float32:
- s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32))
- case float64:
- s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 64))
- case int:
- s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
- case int8:
- s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
- case int16:
- s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
- case int32:
- s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
- case int64:
- s = strconv.FormatInt(v, argInt(args).Get(0, 10))
- case uint:
- s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
- case uint8:
- s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
- case uint16:
- s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
- case uint32:
- s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
- case uint64:
- s = strconv.FormatUint(v, argInt(args).Get(0, 10))
- case string:
- s = v
- case []byte:
- s = string(v)
- default:
- s = fmt.Sprintf("%v", v)
- }
- return s
-}
-
-// ToInt64 interface to int64
-func ToInt64(value interface{}) (d int64) {
- val := reflect.ValueOf(value)
- switch value.(type) {
- case int, int8, int16, int32, int64:
- d = val.Int()
- case uint, uint8, uint16, uint32, uint64:
- d = int64(val.Uint())
- default:
- panic(fmt.Errorf("ToInt64 need numeric not `%T`", value))
- }
- return
-}
-
-func snakeStringWithAcronym(s string) string {
- data := make([]byte, 0, len(s)*2)
- num := len(s)
- for i := 0; i < num; i++ {
- d := s[i]
- before := false
- after := false
- if i > 0 {
- before = s[i-1] >= 'a' && s[i-1] <= 'z'
- }
- if i+1 < num {
- after = s[i+1] >= 'a' && s[i+1] <= 'z'
- }
- if i > 0 && d >= 'A' && d <= 'Z' && (before || after) {
- data = append(data, '_')
- }
- data = append(data, d)
- }
- return strings.ToLower(string(data))
-}
-
-// snake string, XxYy to xx_yy , XxYY to xx_y_y
-func snakeString(s string) string {
- data := make([]byte, 0, len(s)*2)
- j := false
- num := len(s)
- for i := 0; i < num; i++ {
- d := s[i]
- if i > 0 && d >= 'A' && d <= 'Z' && j {
- data = append(data, '_')
- }
- if d != '_' {
- j = true
- }
- data = append(data, d)
- }
- return strings.ToLower(string(data))
-}
-
-// SetNameStrategy set different name strategy
-func SetNameStrategy(s string) {
- if SnakeAcronymNameStrategy != s {
- nameStrategy = defaultNameStrategy
- }
- nameStrategy = s
-}
-
-// camel string, xx_yy to XxYy
-func camelString(s string) string {
- data := make([]byte, 0, len(s))
- flag, num := true, len(s)-1
- for i := 0; i <= num; i++ {
- d := s[i]
- if d == '_' {
- flag = true
- continue
- } else if flag {
- if d >= 'a' && d <= 'z' {
- d = d - 32
- }
- flag = false
- }
- data = append(data, d)
- }
- return string(data)
-}
-
-type argString []string
-
-// Get will get string by index from string slice
-func (a argString) Get(i int, args ...string) (r string) {
- if i >= 0 && i < len(a) {
- r = a[i]
- } else if len(args) > 0 {
- r = args[0]
- }
- return
-}
-
-type argInt []int
-
-// Get will get int by index from int slice
-func (a argInt) Get(i int, args ...int) (r int) {
- if i >= 0 && i < len(a) {
- r = a[i]
- }
- if len(args) > 0 {
- r = args[0]
- }
- return
-}
-
-// timeParse parse time to string with location
-func timeParse(dateString, format string) (time.Time, error) {
- tp, err := time.ParseInLocation(format, dateString, DefaultTimeLoc)
- return tp, err
-}
-
-// indirectType get pointer indirect type
-func indirectType(v reflect.Type) reflect.Type {
- switch v.Kind() {
- case reflect.Ptr:
- return indirectType(v.Elem())
- default:
- return v
- }
-}
diff --git a/adapter/orm/utils_test.go b/adapter/orm/utils_test.go
deleted file mode 100644
index fbf8663e..00000000
--- a/adapter/orm/utils_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestCamelString(t *testing.T) {
- snake := []string{"pic_url", "hello_world_", "hello__World", "_HelLO_Word", "pic_url_1", "pic_url__1"}
- camel := []string{"PicUrl", "HelloWorld", "HelloWorld", "HelLOWord", "PicUrl1", "PicUrl1"}
-
- answer := make(map[string]string)
- for i, v := range snake {
- answer[v] = camel[i]
- }
-
- for _, v := range snake {
- res := camelString(v)
- assert.Equal(t, answer[v], res)
- }
-}
-
-func TestSnakeString(t *testing.T) {
- camel := []string{"PicUrl", "HelloWorld", "HelloWorld", "HelLOWord", "PicUrl1", "XyXX"}
- snake := []string{"pic_url", "hello_world", "hello_world", "hel_l_o_word", "pic_url1", "xy_x_x"}
-
- answer := make(map[string]string)
- for i, v := range camel {
- answer[v] = snake[i]
- }
-
- for _, v := range camel {
- res := snakeString(v)
- assert.Equal(t, answer[v], res)
- }
-}
-
-func TestSnakeStringWithAcronym(t *testing.T) {
- camel := []string{"ID", "PicURL", "HelloWorld", "HelloWorld", "HelLOWord", "PicUrl1", "XyXX"}
- snake := []string{"id", "pic_url", "hello_world", "hello_world", "hel_lo_word", "pic_url1", "xy_xx"}
-
- answer := make(map[string]string)
- for i, v := range camel {
- answer[v] = snake[i]
- }
-
- for _, v := range camel {
- res := snakeStringWithAcronym(v)
- assert.Equal(t, answer[v], res)
- }
-}
diff --git a/adapter/plugins/apiauth/apiauth.go b/adapter/plugins/apiauth/apiauth.go
deleted file mode 100644
index d5511427..00000000
--- a/adapter/plugins/apiauth/apiauth.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 apiauth provides handlers to enable apiauth support.
-//
-// Simple Usage:
-// import(
-// "github.com/beego/beego/v2"
-// "github.com/beego/beego/v2/server/web/filter/apiauth"
-// )
-//
-// func main(){
-// // apiauth every request
-// beego.InsertFilter("*", beego.BeforeRouter,apiauth.APIBaiscAuth("appid","appkey"))
-// beego.Run()
-// }
-//
-// Advanced Usage:
-//
-// func getAppSecret(appid string) string {
-// // get appsecret by appid
-// // maybe store in configure, maybe in database
-// }
-//
-// beego.InsertFilter("*", beego.BeforeRouter,apiauth.APISecretAuth(getAppSecret, 360))
-//
-// Information:
-//
-// In the request user should include these params in the query
-//
-// 1. appid
-//
-// appid is assigned to the application
-//
-// 2. signature
-//
-// get the signature use apiauth.Signature()
-//
-// when you send to server remember use url.QueryEscape()
-//
-// 3. timestamp:
-//
-// send the request time, the format is yyyy-mm-dd HH:ii:ss
-//
-package apiauth
-
-import (
- "net/url"
-
- 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/apiauth"
-)
-
-// AppIDToAppSecret is used to get appsecret throw appid
-type AppIDToAppSecret apiauth.AppIDToAppSecret
-
-// APIBasicAuth use the basic appid/appkey as the AppIdToAppSecret
-func APIBasicAuth(appid, appkey string) beego.FilterFunc {
- f := apiauth.APIBasicAuth(appid, appkey)
- return func(c *context.Context) {
- f((*beecontext.Context)(c))
- }
-}
-
-// APIBaiscAuth calls APIBasicAuth for previous callers
-func APIBaiscAuth(appid, appkey string) beego.FilterFunc {
- return APIBasicAuth(appid, appkey)
-}
-
-// APISecretAuth use AppIdToAppSecret verify and
-func APISecretAuth(f AppIDToAppSecret, timeout int) beego.FilterFunc {
- ft := apiauth.APISecretAuth(apiauth.AppIDToAppSecret(f), timeout)
- return func(ctx *context.Context) {
- ft((*beecontext.Context)(ctx))
- }
-}
-
-// Signature used to generate signature with the appsecret/method/params/RequestURI
-func Signature(appsecret, method string, params url.Values, requestURL string) string {
- return apiauth.Signature(appsecret, method, params, requestURL)
-}
diff --git a/adapter/plugins/apiauth/apiauth_test.go b/adapter/plugins/apiauth/apiauth_test.go
deleted file mode 100644
index 1f56cb0f..00000000
--- a/adapter/plugins/apiauth/apiauth_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package apiauth
-
-import (
- "net/url"
- "testing"
-)
-
-func TestSignature(t *testing.T) {
- appsecret := "beego secret"
- method := "GET"
- RequestURL := "http://localhost/test/url"
- params := make(url.Values)
- params.Add("arg1", "hello")
- params.Add("arg2", "beego")
-
- signature := "mFdpvLh48ca4mDVEItE9++AKKQ/IVca7O/ZyyB8hR58="
- if Signature(appsecret, method, params, RequestURL) != signature {
- t.Error("Signature error")
- }
-}
diff --git a/adapter/plugins/auth/basic.go b/adapter/plugins/auth/basic.go
deleted file mode 100644
index 173252ca..00000000
--- a/adapter/plugins/auth/basic.go
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 auth provides handlers to enable basic auth support.
-// Simple Usage:
-// import(
-// "github.com/beego/beego/v2"
-// "github.com/beego/beego/v2/server/web/filter/auth"
-// )
-//
-// func main(){
-// // authenticate every request
-// beego.InsertFilter("*", beego.BeforeRouter,auth.Basic("username","secretpassword"))
-// beego.Run()
-// }
-//
-//
-// Advanced Usage:
-//
-// func SecretAuth(username, password string) bool {
-// return username == "astaxie" && password == "helloBeego"
-// }
-// authPlugin := auth.NewBasicAuthenticator(SecretAuth, "Authorization Required")
-// beego.InsertFilter("*", beego.BeforeRouter,authPlugin)
-package auth
-
-import (
- "net/http"
-
- 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/auth"
-)
-
-// Basic is the http basic auth
-func Basic(username string, password string) beego.FilterFunc {
- return func(c *context.Context) {
- f := auth.Basic(username, password)
- f((*beecontext.Context)(c))
- }
-}
-
-// NewBasicAuthenticator return the BasicAuth
-func NewBasicAuthenticator(secrets SecretProvider, realm string) beego.FilterFunc {
- f := auth.NewBasicAuthenticator(auth.SecretProvider(secrets), realm)
- return func(c *context.Context) {
- f((*beecontext.Context)(c))
- }
-}
-
-// SecretProvider is the SecretProvider function
-type SecretProvider auth.SecretProvider
-
-// BasicAuth store the SecretProvider and Realm
-type BasicAuth auth.BasicAuth
-
-// CheckAuth Checks the username/password combination from the request. Returns
-// either an empty string (authentication failed) or the name of the
-// authenticated user.
-// Supports MD5 and SHA1 password entries
-func (a *BasicAuth) CheckAuth(r *http.Request) string {
- return (*auth.BasicAuth)(a).CheckAuth(r)
-}
-
-// RequireAuth http.Handler for BasicAuth which initiates the authentication process
-// (or requires reauthentication).
-func (a *BasicAuth) RequireAuth(w http.ResponseWriter, r *http.Request) {
- (*auth.BasicAuth)(a).RequireAuth(w, r)
-}
diff --git a/adapter/plugins/authz/authz.go b/adapter/plugins/authz/authz.go
deleted file mode 100644
index 096d7efb..00000000
--- a/adapter/plugins/authz/authz.go
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 authz provides handlers to enable ACL, RBAC, ABAC authorization support.
-// Simple Usage:
-// import(
-// "github.com/beego/beego/v2"
-// "github.com/beego/beego/v2/server/web/filter/authz"
-// "github.com/casbin/casbin"
-// )
-//
-// func main(){
-// // mediate the access for every request
-// beego.InsertFilter("*", beego.BeforeRouter, authz.NewAuthorizer(casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")))
-// beego.Run()
-// }
-//
-//
-// Advanced Usage:
-//
-// func main(){
-// e := casbin.NewEnforcer("authz_model.conf", "")
-// e.AddRoleForUser("alice", "admin")
-// e.AddPolicy(...)
-//
-// beego.InsertFilter("*", beego.BeforeRouter, authz.NewAuthorizer(e))
-// beego.Run()
-// }
-package authz
-
-import (
- "net/http"
-
- "github.com/casbin/casbin"
-
- 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/authz"
-)
-
-// NewAuthorizer returns the authorizer.
-// Use a casbin enforcer as input
-func NewAuthorizer(e *casbin.Enforcer) beego.FilterFunc {
- f := authz.NewAuthorizer(e)
- return func(context *context.Context) {
- f((*beecontext.Context)(context))
- }
-}
-
-// BasicAuthorizer stores the casbin handler
-type BasicAuthorizer authz.BasicAuthorizer
-
-// GetUserName gets the user name from the request.
-// Currently, only HTTP basic authentication is supported
-func (a *BasicAuthorizer) GetUserName(r *http.Request) string {
- return (*authz.BasicAuthorizer)(a).GetUserName(r)
-}
-
-// CheckPermission checks the user/method/path combination from the request.
-// Returns true (permission granted) or false (permission forbidden)
-func (a *BasicAuthorizer) CheckPermission(r *http.Request) bool {
- return (*authz.BasicAuthorizer)(a).CheckPermission(r)
-}
-
-// RequirePermission returns the 403 Forbidden to the client
-func (a *BasicAuthorizer) RequirePermission(w http.ResponseWriter) {
- (*authz.BasicAuthorizer)(a).RequirePermission(w)
-}
diff --git a/adapter/plugins/authz/authz_model.conf b/adapter/plugins/authz/authz_model.conf
deleted file mode 100644
index fd2f08df..00000000
--- a/adapter/plugins/authz/authz_model.conf
+++ /dev/null
@@ -1,14 +0,0 @@
-[request_definition]
-r = sub, obj, act
-
-[policy_definition]
-p = sub, obj, act
-
-[role_definition]
-g = _, _
-
-[policy_effect]
-e = some(where (p.eft == allow))
-
-[matchers]
-m = g(r.sub, p.sub) && keyMatch(r.obj, p.obj) && (r.act == p.act || p.act == "*")
diff --git a/adapter/plugins/authz/authz_policy.csv b/adapter/plugins/authz/authz_policy.csv
deleted file mode 100644
index 9203e11f..00000000
--- a/adapter/plugins/authz/authz_policy.csv
+++ /dev/null
@@ -1,7 +0,0 @@
-p, alice, /dataset1/*, GET
-p, alice, /dataset1/resource1, POST
-p, bob, /dataset2/resource1, *
-p, bob, /dataset2/resource2, GET
-p, bob, /dataset2/folder1/*, POST
-p, dataset1_admin, /dataset1/*, *
-g, cathy, dataset1_admin
diff --git a/adapter/plugins/authz/authz_test.go b/adapter/plugins/authz/authz_test.go
deleted file mode 100644
index 4963ceab..00000000
--- a/adapter/plugins/authz/authz_test.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 authz
-
-import (
- "net/http"
- "net/http/httptest"
- "testing"
-
- "github.com/casbin/casbin"
-
- beego "github.com/beego/beego/v2/adapter"
- "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/adapter/plugins/auth"
-)
-
-const (
- authCfg = "authz_model.conf"
- authCsv = "authz_policy.csv"
-)
-
-func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) {
- r, _ := http.NewRequest(method, path, nil)
- r.SetBasicAuth(user, "123")
- w := httptest.NewRecorder()
- handler.ServeHTTP(w, r)
-
- if w.Code != code {
- t.Errorf("%s, %s, %s: %d, supposed to be %d", user, path, method, w.Code, code)
- }
-}
-
-func TestBasic(t *testing.T) {
- handler := beego.NewControllerRegister()
-
- _ = handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("alice", "123"))
-
- _ = handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(casbin.NewEnforcer(authCfg, authCsv)))
-
- handler.Any("*", func(ctx *context.Context) {
- ctx.Output.SetStatus(200)
- })
-
- const d1r1 = "/dataset1/resource1"
- testRequest(t, handler, "alice", d1r1, "GET", 200)
- testRequest(t, handler, "alice", d1r1, "POST", 200)
- const d1r2 = "/dataset1/resource2"
- testRequest(t, handler, "alice", d1r2, "GET", 200)
- testRequest(t, handler, "alice", d1r2, "POST", 403)
-}
-
-func TestPathWildcard(t *testing.T) {
- handler := beego.NewControllerRegister()
-
- _ = handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("bob", "123"))
- _ = handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(casbin.NewEnforcer(authCfg, authCsv)))
-
- handler.Any("*", func(ctx *context.Context) {
- ctx.Output.SetStatus(200)
- })
-
- const d2r1 = "/dataset2/resource1"
- testRequest(t, handler, "bob", d2r1, "GET", 200)
- testRequest(t, handler, "bob", d2r1, "POST", 200)
- testRequest(t, handler, "bob", d2r1, "DELETE", 200)
- const d2r2 = "/dataset2/resource2"
- testRequest(t, handler, "bob", d2r2, "GET", 200)
- testRequest(t, handler, "bob", d2r2, "POST", 403)
- testRequest(t, handler, "bob", d2r2, "DELETE", 403)
-
- const item1 = "/dataset2/folder1/item1"
- testRequest(t, handler, "bob", item1, "GET", 403)
- testRequest(t, handler, "bob", item1, "POST", 200)
- testRequest(t, handler, "bob", item1, "DELETE", 403)
- const item2 = "/dataset2/folder1/item2"
- testRequest(t, handler, "bob", item2, "GET", 403)
- testRequest(t, handler, "bob", item2, "POST", 200)
- testRequest(t, handler, "bob", item2, "DELETE", 403)
-}
-
-func TestRBAC(t *testing.T) {
- handler := beego.NewControllerRegister()
-
- _ = handler.InsertFilter("*", beego.BeforeRouter, auth.Basic("cathy", "123"))
- e := casbin.NewEnforcer(authCfg, authCsv)
- _ = handler.InsertFilter("*", beego.BeforeRouter, NewAuthorizer(e))
-
- handler.Any("*", func(ctx *context.Context) {
- ctx.Output.SetStatus(200)
- })
-
- // cathy can access all /dataset1/* resources via all methods because it has the dataset1_admin role.
- const dataSet1 = "/dataset1/item"
- testRequest(t, handler, "cathy", dataSet1, "GET", 200)
- testRequest(t, handler, "cathy", dataSet1, "POST", 200)
- testRequest(t, handler, "cathy", dataSet1, "DELETE", 200)
- const dataSet2 = "/dataset2/item"
- testRequest(t, handler, "cathy", dataSet2, "GET", 403)
- testRequest(t, handler, "cathy", dataSet2, "POST", 403)
- testRequest(t, handler, "cathy", dataSet2, "DELETE", 403)
-
- // delete all roles on user cathy, so cathy cannot access any resources now.
- e.DeleteRolesForUser("cathy")
-
- testRequest(t, handler, "cathy", dataSet1, "GET", 403)
- testRequest(t, handler, "cathy", dataSet1, "POST", 403)
- testRequest(t, handler, "cathy", dataSet1, "DELETE", 403)
- testRequest(t, handler, "cathy", dataSet2, "GET", 403)
- testRequest(t, handler, "cathy", dataSet2, "POST", 403)
- testRequest(t, handler, "cathy", dataSet2, "DELETE", 403)
-}
diff --git a/adapter/plugins/cors/cors.go b/adapter/plugins/cors/cors.go
deleted file mode 100644
index c02ab877..00000000
--- a/adapter/plugins/cors/cors.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 cors provides handlers to enable CORS support.
-// Usage
-// import (
-// "github.com/beego/beego/v2"
-// "github.com/beego/beego/v2/server/web/filter/cors"
-// )
-//
-// func main() {
-// // CORS for https://foo.* origins, allowing:
-// // - PUT and PATCH methods
-// // - Origin header
-// // - Credentials share
-// beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
-// AllowOrigins: []string{"https://*.foo.com"},
-// AllowMethods: []string{"PUT", "PATCH"},
-// AllowHeaders: []string{"Origin"},
-// ExposeHeaders: []string{"Content-Length"},
-// AllowCredentials: true,
-// }))
-// beego.Run()
-// }
-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"
-)
-
-// Options represents Access Control options.
-type Options cors.Options
-
-// Header converts options into CORS headers.
-func (o *Options) Header(origin string) (headers map[string]string) {
- return (*cors.Options)(o).Header(origin)
-}
-
-// PreflightHeader converts options into CORS headers for a preflight response.
-func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string) {
- return (*cors.Options)(o).PreflightHeader(origin, rMethod, rHeaders)
-}
-
-// IsOriginAllowed looks up if the origin matches one of the patterns
-// generated from Options.AllowOrigins patterns.
-func (o *Options) IsOriginAllowed(origin string) bool {
- return (*cors.Options)(o).IsOriginAllowed(origin)
-}
-
-// Allow enables CORS for requests those match the provided options.
-func Allow(opts *Options) beego.FilterFunc {
- f := cors.Allow((*cors.Options)(opts))
- return func(c *context.Context) {
- f((*beecontext.Context)(c))
- }
-}
diff --git a/adapter/policy.go b/adapter/policy.go
deleted file mode 100644
index c0b95601..00000000
--- a/adapter/policy.go
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2016 beego authors. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/server/web"
- beecontext "github.com/beego/beego/v2/server/web/context"
-)
-
-// PolicyFunc defines a policy function which is invoked before the controller handler is executed.
-type PolicyFunc func(*context.Context)
-
-// FindPolicy Find Router info for URL
-func (p *ControllerRegister) FindPolicy(cont *context.Context) []PolicyFunc {
- pf := (*web.ControllerRegister)(p).FindPolicy((*beecontext.Context)(cont))
- npf := newToOldPolicyFunc(pf)
- return npf
-}
-
-func newToOldPolicyFunc(pf []web.PolicyFunc) []PolicyFunc {
- npf := make([]PolicyFunc, 0, len(pf))
- for _, f := range pf {
- npf = append(npf, func(c *context.Context) {
- f((*beecontext.Context)(c))
- })
- }
- return npf
-}
-
-func oldToNewPolicyFunc(pf []PolicyFunc) []web.PolicyFunc {
- npf := make([]web.PolicyFunc, 0, len(pf))
- for _, f := range pf {
- npf = append(npf, func(c *beecontext.Context) {
- f((*context.Context)(c))
- })
- }
- return npf
-}
-
-// Policy Register new policy in beego
-func Policy(pattern, method string, policy ...PolicyFunc) {
- pf := oldToNewPolicyFunc(policy)
- web.Policy(pattern, method, pf...)
-}
diff --git a/adapter/router.go b/adapter/router.go
deleted file mode 100644
index 23f08e1e..00000000
--- a/adapter/router.go
+++ /dev/null
@@ -1,281 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "net/http"
- "time"
-
- beecontext "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/server/web"
- "github.com/beego/beego/v2/server/web/context"
-)
-
-// default filter execution points
-const (
- BeforeStatic = web.BeforeStatic
- BeforeRouter = web.BeforeRouter
- BeforeExec = web.BeforeExec
- AfterExec = web.AfterExec
- FinishRouter = web.FinishRouter
-)
-
-var (
- // HTTPMETHOD list the supported http methods.
- HTTPMETHOD = web.HTTPMETHOD
-
- // DefaultAccessLogFilter will skip the accesslog if return true
- DefaultAccessLogFilter FilterHandler = &newToOldFtHdlAdapter{
- delegate: web.DefaultAccessLogFilter,
- }
-)
-
-// FilterHandler is an interface for
-type FilterHandler interface {
- Filter(*beecontext.Context) bool
-}
-
-type newToOldFtHdlAdapter struct {
- delegate web.FilterHandler
-}
-
-func (n *newToOldFtHdlAdapter) Filter(ctx *beecontext.Context) bool {
- return n.delegate.Filter((*context.Context)(ctx))
-}
-
-// ExceptMethodAppend to append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
-func ExceptMethodAppend(action string) {
- web.ExceptMethodAppend(action)
-}
-
-// ControllerInfo holds information about the controller.
-type ControllerInfo web.ControllerInfo
-
-func (c *ControllerInfo) GetPattern() string {
- return (*web.ControllerInfo)(c).GetPattern()
-}
-
-// ControllerRegister containers registered router rules, controller handlers and filters.
-type ControllerRegister web.ControllerRegister
-
-// NewControllerRegister returns a new ControllerRegister.
-func NewControllerRegister() *ControllerRegister {
- return (*ControllerRegister)(web.NewControllerRegister())
-}
-
-// Add controller handler and pattern rules to ControllerRegister.
-// usage:
-// default methods is the same name as method
-// Add("/user",&UserController{})
-// Add("/api/list",&RestController{},"*:ListFood")
-// Add("/api/create",&RestController{},"post:CreateFood")
-// Add("/api/update",&RestController{},"put:UpdateFood")
-// Add("/api/delete",&RestController{},"delete:DeleteFood")
-// Add("/api",&RestController{},"get,post:ApiFunc"
-// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
-func (p *ControllerRegister) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
- (*web.ControllerRegister)(p).Add(pattern, c, web.WithRouterMethods(c, mappingMethods...))
-}
-
-// Include only when the Runmode is dev will generate router file in the router/auto.go from the controller
-// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
-func (p *ControllerRegister) Include(cList ...ControllerInterface) {
- nls := oldToNewCtrlIntfs(cList)
- (*web.ControllerRegister)(p).Include(nls...)
-}
-
-// GetContext returns a context from pool, so usually you should remember to call Reset function to clean the context
-// And don't forget to give back context to pool
-// example:
-// ctx := p.GetContext()
-// ctx.Reset(w, q)
-// defer p.GiveBackContext(ctx)
-func (p *ControllerRegister) GetContext() *beecontext.Context {
- return (*beecontext.Context)((*web.ControllerRegister)(p).GetContext())
-}
-
-// GiveBackContext put the ctx into pool so that it could be reuse
-func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
- (*web.ControllerRegister)(p).GiveBackContext((*context.Context)(ctx))
-}
-
-// Get add get method
-// usage:
-// Get("/", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Get(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Get(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Post add post method
-// usage:
-// Post("/api", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Post(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Post(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Put add put method
-// usage:
-// Put("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Put(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Put(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Delete add delete method
-// usage:
-// Delete("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Delete(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Delete(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Head add head method
-// usage:
-// Head("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Head(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Head(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Patch add patch method
-// usage:
-// Patch("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Patch(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Patch(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Options add options method
-// usage:
-// Options("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Options(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Options(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Any add all method
-// usage:
-// Any("/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) Any(pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).Any(pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// AddMethod add http method router
-// usage:
-// AddMethod("get","/api/:id", func(ctx *context.Context){
-// ctx.Output.Body("hello world")
-// })
-func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
- (*web.ControllerRegister)(p).AddMethod(method, pattern, func(ctx *context.Context) {
- f((*beecontext.Context)(ctx))
- })
-}
-
-// Handler add user defined Handler
-func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...interface{}) {
- (*web.ControllerRegister)(p).Handler(pattern, h, options...)
-}
-
-// AddAuto router to ControllerRegister.
-// example beego.AddAuto(&MainController{}),
-// MainController has method List and Page.
-// visit the url /main/list to execute List function
-// /main/page to execute Page function.
-func (p *ControllerRegister) AddAuto(c ControllerInterface) {
- (*web.ControllerRegister)(p).AddAuto(c)
-}
-
-// AddAutoPrefix Add auto router to ControllerRegister with prefix.
-// example beego.AddAutoPrefix("/admin",&MainController{}),
-// MainController has method List and Page.
-// visit the url /admin/main/list to execute List function
-// /admin/main/page to execute Page function.
-func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface) {
- (*web.ControllerRegister)(p).AddAutoPrefix(prefix, c)
-}
-
-// InsertFilter Add a FilterFunc with pattern rule and action constant.
-// params is for:
-// 1. setting the returnOnOutput value (false allows multiple filters to execute)
-// 2. determining whether or not params need to be reset.
-func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
- opts := oldToNewFilterOpts(params)
- return (*web.ControllerRegister)(p).InsertFilter(pattern, pos, func(ctx *context.Context) {
- filter((*beecontext.Context)(ctx))
- }, opts...)
-}
-
-func oldToNewFilterOpts(params []bool) []web.FilterOpt {
- opts := make([]web.FilterOpt, 0, 4)
- if len(params) > 0 {
- opts = append(opts, web.WithReturnOnOutput(params[0]))
- } else {
- // the default value should be true
- opts = append(opts, web.WithReturnOnOutput(true))
- }
- if len(params) > 1 {
- opts = append(opts, web.WithResetParams(params[1]))
- }
- return opts
-}
-
-// URLFor does another controller handler in this request function.
-// it can access any controller method.
-func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) string {
- return (*web.ControllerRegister)(p).URLFor(endpoint, values...)
-}
-
-// Implement http.Handler interface.
-func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
- (*web.ControllerRegister)(p).ServeHTTP(rw, r)
-}
-
-// FindRouter Find Router info for URL
-func (p *ControllerRegister) FindRouter(ctx *beecontext.Context) (routerInfo *ControllerInfo, isFind bool) {
- r, ok := (*web.ControllerRegister)(p).FindRouter((*context.Context)(ctx))
- return (*ControllerInfo)(r), ok
-}
-
-// LogAccess logging info HTTP Access
-func LogAccess(ctx *beecontext.Context, startTime *time.Time, statusCode int) {
- web.LogAccess((*context.Context)(ctx), startTime, statusCode)
-}
diff --git a/adapter/session/couchbase/sess_couchbase.go b/adapter/session/couchbase/sess_couchbase.go
deleted file mode 100644
index 9e37e56b..00000000
--- a/adapter/session/couchbase/sess_couchbase.go
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 couchbase for session provider
-//
-// depend on github.com/couchbaselabs/go-couchbasee
-//
-// go install github.com/couchbaselabs/go-couchbase
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/couchbase"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("couchbase", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}``)
-// go globalSessions.GC()
-// }
-//
-package couchbase
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- beecb "github.com/beego/beego/v2/server/web/session/couchbase"
-)
-
-// SessionStore store each session
-type SessionStore beecb.SessionStore
-
-// Provider couchabse provided
-type Provider beecb.Provider
-
-// Set value to couchabse session
-func (cs *SessionStore) Set(key, value interface{}) error {
- return (*beecb.SessionStore)(cs).Set(context.Background(), key, value)
-}
-
-// Get value from couchabse session
-func (cs *SessionStore) Get(key interface{}) interface{} {
- return (*beecb.SessionStore)(cs).Get(context.Background(), key)
-}
-
-// Delete value in couchbase session by given key
-func (cs *SessionStore) Delete(key interface{}) error {
- return (*beecb.SessionStore)(cs).Delete(context.Background(), key)
-}
-
-// Flush Clean all values in couchbase session
-func (cs *SessionStore) Flush() error {
- return (*beecb.SessionStore)(cs).Flush(context.Background())
-}
-
-// SessionID Get couchbase session store id
-func (cs *SessionStore) SessionID() string {
- return (*beecb.SessionStore)(cs).SessionID(context.Background())
-}
-
-// SessionRelease Write couchbase session with Gob string
-func (cs *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*beecb.SessionStore)(cs).SessionRelease(context.Background(), w)
-}
-
-// SessionInit init couchbase session
-// savepath like couchbase server REST/JSON URL
-// e.g. http://host:port/, Pool, Bucket
-func (cp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*beecb.Provider)(cp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read couchbase session by sid
-func (cp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*beecb.Provider)(cp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist Check couchbase session exist.
-// it checkes sid exist or not.
-func (cp *Provider) SessionExist(sid string) bool {
- res, _ := (*beecb.Provider)(cp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate remove oldsid and use sid to generate new session
-func (cp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*beecb.Provider)(cp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy Remove bucket in this couchbase
-func (cp *Provider) SessionDestroy(sid string) error {
- return (*beecb.Provider)(cp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Recycle
-func (cp *Provider) SessionGC() {
- (*beecb.Provider)(cp).SessionGC(context.Background())
-}
-
-// SessionAll return all active session
-func (cp *Provider) SessionAll() int {
- return (*beecb.Provider)(cp).SessionAll(context.Background())
-}
diff --git a/adapter/session/ledis/ledis_session.go b/adapter/session/ledis/ledis_session.go
deleted file mode 100644
index c42c1787..00000000
--- a/adapter/session/ledis/ledis_session.go
+++ /dev/null
@@ -1,86 +0,0 @@
-// Package ledis provide session Provider
-package ledis
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- beeLedis "github.com/beego/beego/v2/server/web/session/ledis"
-)
-
-// SessionStore ledis session store
-type SessionStore beeLedis.SessionStore
-
-// Set value in ledis session
-func (ls *SessionStore) Set(key, value interface{}) error {
- return (*beeLedis.SessionStore)(ls).Set(context.Background(), key, value)
-}
-
-// Get value in ledis session
-func (ls *SessionStore) Get(key interface{}) interface{} {
- return (*beeLedis.SessionStore)(ls).Get(context.Background(), key)
-}
-
-// Delete value in ledis session
-func (ls *SessionStore) Delete(key interface{}) error {
- return (*beeLedis.SessionStore)(ls).Delete(context.Background(), key)
-}
-
-// Flush clear all values in ledis session
-func (ls *SessionStore) Flush() error {
- return (*beeLedis.SessionStore)(ls).Flush(context.Background())
-}
-
-// SessionID get ledis session id
-func (ls *SessionStore) SessionID() string {
- return (*beeLedis.SessionStore)(ls).SessionID(context.Background())
-}
-
-// SessionRelease save session values to ledis
-func (ls *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*beeLedis.SessionStore)(ls).SessionRelease(context.Background(), w)
-}
-
-// Provider ledis session provider
-type Provider beeLedis.Provider
-
-// SessionInit init ledis session
-// savepath like ledis server saveDataPath,pool size
-// e.g. 127.0.0.1:6379,100,astaxie
-func (lp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*beeLedis.Provider)(lp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read ledis session by sid
-func (lp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*beeLedis.Provider)(lp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check ledis session exist by sid
-func (lp *Provider) SessionExist(sid string) bool {
- res, _ := (*beeLedis.Provider)(lp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for ledis session
-func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*beeLedis.Provider)(lp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete ledis session by id
-func (lp *Provider) SessionDestroy(sid string) error {
- return (*beeLedis.Provider)(lp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Impelment method, no used.
-func (lp *Provider) SessionGC() {
- (*beeLedis.Provider)(lp).SessionGC(context.Background())
-}
-
-// SessionAll return all active session
-func (lp *Provider) SessionAll() int {
- return (*beeLedis.Provider)(lp).SessionAll(context.Background())
-}
diff --git a/adapter/session/memcache/sess_memcache.go b/adapter/session/memcache/sess_memcache.go
deleted file mode 100644
index 4ca779f7..00000000
--- a/adapter/session/memcache/sess_memcache.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 memcache for session provider
-//
-// depend on github.com/bradfitz/gomemcache/memcache
-//
-// go install github.com/bradfitz/gomemcache/memcache
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/memcache"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("memcache", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}``)
-// go globalSessions.GC()
-// }
-//
-package memcache
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- beemem "github.com/beego/beego/v2/server/web/session/memcache"
-)
-
-// SessionStore memcache session store
-type SessionStore beemem.SessionStore
-
-// Set value in memcache session
-func (rs *SessionStore) Set(key, value interface{}) error {
- return (*beemem.SessionStore)(rs).Set(context.Background(), key, value)
-}
-
-// Get value in memcache session
-func (rs *SessionStore) Get(key interface{}) interface{} {
- return (*beemem.SessionStore)(rs).Get(context.Background(), key)
-}
-
-// Delete value in memcache session
-func (rs *SessionStore) Delete(key interface{}) error {
- return (*beemem.SessionStore)(rs).Delete(context.Background(), key)
-}
-
-// Flush clear all values in memcache session
-func (rs *SessionStore) Flush() error {
- return (*beemem.SessionStore)(rs).Flush(context.Background())
-}
-
-// SessionID get memcache session id
-func (rs *SessionStore) SessionID() string {
- return (*beemem.SessionStore)(rs).SessionID(context.Background())
-}
-
-// SessionRelease save session values to memcache
-func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*beemem.SessionStore)(rs).SessionRelease(context.Background(), w)
-}
-
-// MemProvider memcache session provider
-type MemProvider beemem.MemProvider
-
-// SessionInit init memcache session
-// savepath like
-// e.g. 127.0.0.1:9090
-func (rp *MemProvider) SessionInit(maxlifetime int64, savePath string) error {
- return (*beemem.MemProvider)(rp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read memcache session by sid
-func (rp *MemProvider) SessionRead(sid string) (session.Store, error) {
- s, err := (*beemem.MemProvider)(rp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check memcache session exist by sid
-func (rp *MemProvider) SessionExist(sid string) bool {
- res, _ := (*beemem.MemProvider)(rp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for memcache session
-func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*beemem.MemProvider)(rp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete memcache session by id
-func (rp *MemProvider) SessionDestroy(sid string) error {
- return (*beemem.MemProvider)(rp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Impelment method, no used.
-func (rp *MemProvider) SessionGC() {
- (*beemem.MemProvider)(rp).SessionGC(context.Background())
-}
-
-// SessionAll return all activeSession
-func (rp *MemProvider) SessionAll() int {
- return (*beemem.MemProvider)(rp).SessionAll(context.Background())
-}
diff --git a/adapter/session/mysql/sess_mysql.go b/adapter/session/mysql/sess_mysql.go
deleted file mode 100644
index eb2bd090..00000000
--- a/adapter/session/mysql/sess_mysql.go
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 mysql for session provider
-//
-// depends on github.com/go-sql-driver/mysql:
-//
-// go install github.com/go-sql-driver/mysql
-//
-// mysql session support need create table as sql:
-// CREATE TABLE `session` (
-// `session_key` char(64) NOT NULL,
-// `session_data` blob,
-// `session_expiry` int(11) unsigned NOT NULL,
-// PRIMARY KEY (`session_key`)
-// ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/mysql"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("mysql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]"}``)
-// go globalSessions.GC()
-// }
-//
-package mysql
-
-import (
- "context"
- "net/http"
-
- _ "github.com/go-sql-driver/mysql"
-
- "github.com/beego/beego/v2/adapter/session"
- "github.com/beego/beego/v2/server/web/session/mysql"
-)
-
-var (
- // TableName store the session in MySQL
- TableName = mysql.TableName
- mysqlpder = &Provider{}
-)
-
-// SessionStore mysql session store
-type SessionStore mysql.SessionStore
-
-// Set value in mysql session.
-// it is temp value in map.
-func (st *SessionStore) Set(key, value interface{}) error {
- return (*mysql.SessionStore)(st).Set(context.Background(), key, value)
-}
-
-// Get value from mysql session
-func (st *SessionStore) Get(key interface{}) interface{} {
- return (*mysql.SessionStore)(st).Get(context.Background(), key)
-}
-
-// Delete value in mysql session
-func (st *SessionStore) Delete(key interface{}) error {
- return (*mysql.SessionStore)(st).Delete(context.Background(), key)
-}
-
-// Flush clear all values in mysql session
-func (st *SessionStore) Flush() error {
- return (*mysql.SessionStore)(st).Flush(context.Background())
-}
-
-// SessionID get session id of this mysql session store
-func (st *SessionStore) SessionID() string {
- return (*mysql.SessionStore)(st).SessionID(context.Background())
-}
-
-// SessionRelease save mysql session values to database.
-// must call this method to save values to database.
-func (st *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*mysql.SessionStore)(st).SessionRelease(context.Background(), w)
-}
-
-// Provider mysql session provider
-type Provider mysql.Provider
-
-// SessionInit init mysql session.
-// savepath is the connection string of mysql.
-func (mp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*mysql.Provider)(mp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead get mysql session by sid
-func (mp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*mysql.Provider)(mp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check mysql session exist
-func (mp *Provider) SessionExist(sid string) bool {
- res, _ := (*mysql.Provider)(mp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for mysql session
-func (mp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*mysql.Provider)(mp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete mysql session by sid
-func (mp *Provider) SessionDestroy(sid string) error {
- return (*mysql.Provider)(mp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC delete expired values in mysql session
-func (mp *Provider) SessionGC() {
- (*mysql.Provider)(mp).SessionGC(context.Background())
-}
-
-// SessionAll count values in mysql session
-func (mp *Provider) SessionAll() int {
- return (*mysql.Provider)(mp).SessionAll(context.Background())
-}
diff --git a/adapter/session/postgres/sess_postgresql.go b/adapter/session/postgres/sess_postgresql.go
deleted file mode 100644
index b50e3c59..00000000
--- a/adapter/session/postgres/sess_postgresql.go
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 postgres for session provider
-//
-// depends on github.com/lib/pq:
-//
-// go install github.com/lib/pq
-//
-//
-// needs this table in your database:
-//
-// CREATE TABLE session (
-// session_key char(64) NOT NULL,
-// session_data bytea,
-// session_expiry timestamp NOT NULL,
-// CONSTRAINT session_key PRIMARY KEY(session_key)
-// );
-//
-// will be activated with these settings in app.conf:
-//
-// SessionOn = true
-// SessionProvider = postgresql
-// SessionSavePath = "user=a password=b dbname=c sslmode=disable"
-// SessionName = session
-//
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/postgresql"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("postgresql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}``)
-// go globalSessions.GC()
-// }
-//
-package postgres
-
-import (
- "context"
- "net/http"
-
- _ "github.com/lib/pq"
-
- "github.com/beego/beego/v2/adapter/session"
- "github.com/beego/beego/v2/server/web/session/postgres"
-)
-
-// SessionStore postgresql session store
-type SessionStore postgres.SessionStore
-
-// Set value in postgresql session.
-// it is temp value in map.
-func (st *SessionStore) Set(key, value interface{}) error {
- return (*postgres.SessionStore)(st).Set(context.Background(), key, value)
-}
-
-// Get value from postgresql session
-func (st *SessionStore) Get(key interface{}) interface{} {
- return (*postgres.SessionStore)(st).Get(context.Background(), key)
-}
-
-// Delete value in postgresql session
-func (st *SessionStore) Delete(key interface{}) error {
- return (*postgres.SessionStore)(st).Delete(context.Background(), key)
-}
-
-// Flush clear all values in postgresql session
-func (st *SessionStore) Flush() error {
- return (*postgres.SessionStore)(st).Flush(context.Background())
-}
-
-// SessionID get session id of this postgresql session store
-func (st *SessionStore) SessionID() string {
- return (*postgres.SessionStore)(st).SessionID(context.Background())
-}
-
-// SessionRelease save postgresql session values to database.
-// must call this method to save values to database.
-func (st *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*postgres.SessionStore)(st).SessionRelease(context.Background(), w)
-}
-
-// Provider postgresql session provider
-type Provider postgres.Provider
-
-// SessionInit init postgresql session.
-// savepath is the connection string of postgresql.
-func (mp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*postgres.Provider)(mp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead get postgresql session by sid
-func (mp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*postgres.Provider)(mp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check postgresql session exist
-func (mp *Provider) SessionExist(sid string) bool {
- res, _ := (*postgres.Provider)(mp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for postgresql session
-func (mp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*postgres.Provider)(mp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete postgresql session by sid
-func (mp *Provider) SessionDestroy(sid string) error {
- return (*postgres.Provider)(mp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC delete expired values in postgresql session
-func (mp *Provider) SessionGC() {
- (*postgres.Provider)(mp).SessionGC(context.Background())
-}
-
-// SessionAll count values in postgresql session
-func (mp *Provider) SessionAll() int {
- return (*postgres.Provider)(mp).SessionAll(context.Background())
-}
diff --git a/adapter/session/provider_adapter.go b/adapter/session/provider_adapter.go
deleted file mode 100644
index 3e62aa63..00000000
--- a/adapter/session/provider_adapter.go
+++ /dev/null
@@ -1,104 +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 session
-
-import (
- "context"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-type oldToNewProviderAdapter struct {
- delegate Provider
-}
-
-func (o *oldToNewProviderAdapter) SessionInit(ctx context.Context, gclifetime int64, config string) error {
- return o.delegate.SessionInit(gclifetime, config)
-}
-
-func (o *oldToNewProviderAdapter) SessionRead(ctx context.Context, sid string) (session.Store, error) {
- store, err := o.delegate.SessionRead(sid)
- return &oldToNewStoreAdapter{
- delegate: store,
- }, err
-}
-
-func (o *oldToNewProviderAdapter) SessionExist(ctx context.Context, sid string) (bool, error) {
- return o.delegate.SessionExist(sid), nil
-}
-
-func (o *oldToNewProviderAdapter) SessionRegenerate(ctx context.Context, oldsid, sid string) (session.Store, error) {
- s, err := o.delegate.SessionRegenerate(oldsid, sid)
- return &oldToNewStoreAdapter{
- delegate: s,
- }, err
-}
-
-func (o *oldToNewProviderAdapter) SessionDestroy(ctx context.Context, sid string) error {
- return o.delegate.SessionDestroy(sid)
-}
-
-func (o *oldToNewProviderAdapter) SessionAll(ctx context.Context) int {
- return o.delegate.SessionAll()
-}
-
-func (o *oldToNewProviderAdapter) SessionGC(ctx context.Context) {
- o.delegate.SessionGC()
-}
-
-type newToOldProviderAdapter struct {
- delegate session.Provider
-}
-
-func (n *newToOldProviderAdapter) SessionInit(gclifetime int64, config string) error {
- return n.delegate.SessionInit(context.Background(), gclifetime, config)
-}
-
-func (n *newToOldProviderAdapter) SessionRead(sid string) (Store, error) {
- s, err := n.delegate.SessionRead(context.Background(), sid)
- if adt, ok := s.(*oldToNewStoreAdapter); err == nil && ok {
- return adt.delegate, err
- }
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-func (n *newToOldProviderAdapter) SessionExist(sid string) bool {
- res, _ := n.delegate.SessionExist(context.Background(), sid)
- return res
-}
-
-func (n *newToOldProviderAdapter) SessionRegenerate(oldsid, sid string) (Store, error) {
- s, err := n.delegate.SessionRegenerate(context.Background(), oldsid, sid)
- if adt, ok := s.(*oldToNewStoreAdapter); err == nil && ok {
- return adt.delegate, err
- }
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-func (n *newToOldProviderAdapter) SessionDestroy(sid string) error {
- return n.delegate.SessionDestroy(context.Background(), sid)
-}
-
-func (n *newToOldProviderAdapter) SessionAll() int {
- return n.delegate.SessionAll(context.Background())
-}
-
-func (n *newToOldProviderAdapter) SessionGC() {
- n.delegate.SessionGC(context.Background())
-}
diff --git a/adapter/session/redis/sess_redis.go b/adapter/session/redis/sess_redis.go
deleted file mode 100644
index 7d3287ff..00000000
--- a/adapter/session/redis/sess_redis.go
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 redis for session provider
-//
-// depend on github.com/gomodule/redigo/redis
-//
-// go install github.com/gomodule/redigo/redis
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/redis"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("redis", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}``)
-// go globalSessions.GC()
-// }
-//
-package redis
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- beeRedis "github.com/beego/beego/v2/server/web/session/redis"
-)
-
-// MaxPoolSize redis max pool size
-var MaxPoolSize = beeRedis.MaxPoolSize
-
-// SessionStore redis session store
-type SessionStore beeRedis.SessionStore
-
-// Set value in redis session
-func (rs *SessionStore) Set(key, value interface{}) error {
- return (*beeRedis.SessionStore)(rs).Set(context.Background(), key, value)
-}
-
-// Get value in redis session
-func (rs *SessionStore) Get(key interface{}) interface{} {
- return (*beeRedis.SessionStore)(rs).Get(context.Background(), key)
-}
-
-// Delete value in redis session
-func (rs *SessionStore) Delete(key interface{}) error {
- return (*beeRedis.SessionStore)(rs).Delete(context.Background(), key)
-}
-
-// Flush clear all values in redis session
-func (rs *SessionStore) Flush() error {
- return (*beeRedis.SessionStore)(rs).Flush(context.Background())
-}
-
-// SessionID get redis session id
-func (rs *SessionStore) SessionID() string {
- return (*beeRedis.SessionStore)(rs).SessionID(context.Background())
-}
-
-// SessionRelease save session values to redis
-func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*beeRedis.SessionStore)(rs).SessionRelease(context.Background(), w)
-}
-
-// Provider redis session provider
-type Provider beeRedis.Provider
-
-// SessionInit init redis session
-// savepath like redis server addr,pool size,password,dbnum,IdleTimeout second
-// e.g. 127.0.0.1:6379,100,astaxie,0,30
-func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*beeRedis.Provider)(rp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read redis session by sid
-func (rp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*beeRedis.Provider)(rp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check redis session exist by sid
-func (rp *Provider) SessionExist(sid string) bool {
- res, _ := (*beeRedis.Provider)(rp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for redis session
-func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*beeRedis.Provider)(rp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete redis session by id
-func (rp *Provider) SessionDestroy(sid string) error {
- return (*beeRedis.Provider)(rp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Impelment method, no used.
-func (rp *Provider) SessionGC() {
- (*beeRedis.Provider)(rp).SessionGC(context.Background())
-}
-
-// SessionAll return all activeSession
-func (rp *Provider) SessionAll() int {
- return (*beeRedis.Provider)(rp).SessionAll(context.Background())
-}
diff --git a/adapter/session/redis_cluster/redis_cluster.go b/adapter/session/redis_cluster/redis_cluster.go
deleted file mode 100644
index 4b9c09b4..00000000
--- a/adapter/session/redis_cluster/redis_cluster.go
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 redis for session provider
-//
-// depend on github.com/go-redis/redis
-//
-// go install github.com/go-redis/redis
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/redis_cluster"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("redis_cluster", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070;127.0.0.1:7071"}``)
-// go globalSessions.GC()
-// }
-//
-package redis_cluster
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- cluster "github.com/beego/beego/v2/server/web/session/redis_cluster"
-)
-
-// MaxPoolSize redis_cluster max pool size
-var MaxPoolSize = cluster.MaxPoolSize
-
-// SessionStore redis_cluster session store
-type SessionStore cluster.SessionStore
-
-// Set value in redis_cluster session
-func (rs *SessionStore) Set(key, value interface{}) error {
- return (*cluster.SessionStore)(rs).Set(context.Background(), key, value)
-}
-
-// Get value in redis_cluster session
-func (rs *SessionStore) Get(key interface{}) interface{} {
- return (*cluster.SessionStore)(rs).Get(context.Background(), key)
-}
-
-// Delete value in redis_cluster session
-func (rs *SessionStore) Delete(key interface{}) error {
- return (*cluster.SessionStore)(rs).Delete(context.Background(), key)
-}
-
-// Flush clear all values in redis_cluster session
-func (rs *SessionStore) Flush() error {
- return (*cluster.SessionStore)(rs).Flush(context.Background())
-}
-
-// SessionID get redis_cluster session id
-func (rs *SessionStore) SessionID() string {
- return (*cluster.SessionStore)(rs).SessionID(context.Background())
-}
-
-// SessionRelease save session values to redis_cluster
-func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*cluster.SessionStore)(rs).SessionRelease(context.Background(), w)
-}
-
-// Provider redis_cluster session provider
-type Provider cluster.Provider
-
-// SessionInit init redis_cluster session
-// savepath like redis server addr,pool size,password,dbnum
-// e.g. 127.0.0.1:6379;127.0.0.1:6380,100,test,0
-func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*cluster.Provider)(rp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read redis_cluster session by sid
-func (rp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*cluster.Provider)(rp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check redis_cluster session exist by sid
-func (rp *Provider) SessionExist(sid string) bool {
- res, _ := (*cluster.Provider)(rp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for redis_cluster session
-func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*cluster.Provider)(rp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete redis session by id
-func (rp *Provider) SessionDestroy(sid string) error {
- return (*cluster.Provider)(rp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Impelment method, no used.
-func (rp *Provider) SessionGC() {
- (*cluster.Provider)(rp).SessionGC(context.Background())
-}
-
-// SessionAll return all activeSession
-func (rp *Provider) SessionAll() int {
- return (*cluster.Provider)(rp).SessionAll(context.Background())
-}
diff --git a/adapter/session/redis_sentinel/sess_redis_sentinel.go b/adapter/session/redis_sentinel/sess_redis_sentinel.go
deleted file mode 100644
index 633fb5fa..00000000
--- a/adapter/session/redis_sentinel/sess_redis_sentinel.go
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 redis for session provider
-//
-// depend on github.com/go-redis/redis
-//
-// go install github.com/go-redis/redis
-//
-// Usage:
-// import(
-// _ "github.com/beego/beego/v2/server/web/session/redis_sentinel"
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("redis_sentinel", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:26379;127.0.0.2:26379"}``)
-// go globalSessions.GC()
-// }
-//
-// more detail about params: please check the notes on the function SessionInit in this package
-package redis_sentinel
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- sentinel "github.com/beego/beego/v2/server/web/session/redis_sentinel"
-)
-
-// DefaultPoolSize redis_sentinel default pool size
-var DefaultPoolSize = sentinel.DefaultPoolSize
-
-// SessionStore redis_sentinel session store
-type SessionStore sentinel.SessionStore
-
-// Set value in redis_sentinel session
-func (rs *SessionStore) Set(key, value interface{}) error {
- return (*sentinel.SessionStore)(rs).Set(context.Background(), key, value)
-}
-
-// Get value in redis_sentinel session
-func (rs *SessionStore) Get(key interface{}) interface{} {
- return (*sentinel.SessionStore)(rs).Get(context.Background(), key)
-}
-
-// Delete value in redis_sentinel session
-func (rs *SessionStore) Delete(key interface{}) error {
- return (*sentinel.SessionStore)(rs).Delete(context.Background(), key)
-}
-
-// Flush clear all values in redis_sentinel session
-func (rs *SessionStore) Flush() error {
- return (*sentinel.SessionStore)(rs).Flush(context.Background())
-}
-
-// SessionID get redis_sentinel session id
-func (rs *SessionStore) SessionID() string {
- return (*sentinel.SessionStore)(rs).SessionID(context.Background())
-}
-
-// SessionRelease save session values to redis_sentinel
-func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*sentinel.SessionStore)(rs).SessionRelease(context.Background(), w)
-}
-
-// Provider redis_sentinel session provider
-type Provider sentinel.Provider
-
-// SessionInit init redis_sentinel session
-// savepath like redis sentinel addr,pool size,password,dbnum,masterName
-// e.g. 127.0.0.1:26379;127.0.0.2:26379,100,1qaz2wsx,0,mymaster
-func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
- return (*sentinel.Provider)(rp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead read redis_sentinel session by sid
-func (rp *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*sentinel.Provider)(rp).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist check redis_sentinel session exist by sid
-func (rp *Provider) SessionExist(sid string) bool {
- res, _ := (*sentinel.Provider)(rp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for redis_sentinel session
-func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*sentinel.Provider)(rp).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy delete redis session by id
-func (rp *Provider) SessionDestroy(sid string) error {
- return (*sentinel.Provider)(rp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Impelment method, no used.
-func (rp *Provider) SessionGC() {
- (*sentinel.Provider)(rp).SessionGC(context.Background())
-}
-
-// SessionAll return all activeSession
-func (rp *Provider) SessionAll() int {
- return (*sentinel.Provider)(rp).SessionAll(context.Background())
-}
diff --git a/adapter/session/redis_sentinel/sess_redis_sentinel_test.go b/adapter/session/redis_sentinel/sess_redis_sentinel_test.go
deleted file mode 100644
index 2d381af6..00000000
--- a/adapter/session/redis_sentinel/sess_redis_sentinel_test.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package redis_sentinel
-
-import (
- "net/http"
- "net/http/httptest"
- "testing"
-
- "github.com/stretchr/testify/assert"
-
- "github.com/beego/beego/v2/adapter/session"
-)
-
-func TestRedisSentinel(t *testing.T) {
- sessionConfig := &session.ManagerConfig{
- CookieName: "gosessionid",
- EnableSetCookie: true,
- Gclifetime: 3600,
- Maxlifetime: 3600,
- Secure: false,
- CookieLifeTime: 3600,
- ProviderConfig: "127.0.0.1:6379,100,,0,master",
- }
- globalSessions, e := session.NewManager("redis_sentinel", sessionConfig)
-
- if e != nil {
- t.Log(e)
- return
- }
-
- go globalSessions.GC()
-
- r, _ := http.NewRequest("GET", "/", nil)
- w := httptest.NewRecorder()
-
- sess, err := globalSessions.SessionStart(w, r)
- assert.Nil(t, err)
- defer sess.SessionRelease(w)
-
- // SET AND GET
- err = sess.Set("username", "astaxie")
- assert.Nil(t, err)
- username := sess.Get("username")
- assert.Equal(t, "astaxie", username)
-
- // DELETE
- err = sess.Delete("username")
- assert.Nil(t, err)
-
- username = sess.Get("username")
- assert.Nil(t, username)
-
- // FLUSH
- err = sess.Set("username", "astaxie")
- assert.Nil(t, err)
-
- err = sess.Set("password", "1qaz2wsx")
- assert.Nil(t, err)
-
- username = sess.Get("username")
- assert.Equal(t, "astaxie", username)
-
- password := sess.Get("password")
- assert.Equal(t, "1qaz2wsx", password)
-
- err = sess.Flush()
- assert.Nil(t, err)
-
- username = sess.Get("username")
- assert.Nil(t, username)
-
- password = sess.Get("password")
- assert.Nil(t, password)
-
- sess.SessionRelease(w)
-}
diff --git a/adapter/session/sess_cookie.go b/adapter/session/sess_cookie.go
deleted file mode 100644
index ef3b6799..00000000
--- a/adapter/session/sess_cookie.go
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-// CookieSessionStore Cookie SessionStore
-type CookieSessionStore session.CookieSessionStore
-
-// Set value to cookie session.
-// the value are encoded as gob with hash block string.
-func (st *CookieSessionStore) Set(key, value interface{}) error {
- return (*session.CookieSessionStore)(st).Set(context.Background(), key, value)
-}
-
-// Get value from cookie session
-func (st *CookieSessionStore) Get(key interface{}) interface{} {
- return (*session.CookieSessionStore)(st).Get(context.Background(), key)
-}
-
-// Delete value in cookie session
-func (st *CookieSessionStore) Delete(key interface{}) error {
- return (*session.CookieSessionStore)(st).Delete(context.Background(), key)
-}
-
-// Flush Clean all values in cookie session
-func (st *CookieSessionStore) Flush() error {
- return (*session.CookieSessionStore)(st).Flush(context.Background())
-}
-
-// SessionID Return id of this cookie session
-func (st *CookieSessionStore) SessionID() string {
- return (*session.CookieSessionStore)(st).SessionID(context.Background())
-}
-
-// SessionRelease Write cookie session to http response cookie
-func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter) {
- (*session.CookieSessionStore)(st).SessionRelease(context.Background(), w)
-}
-
-// CookieProvider Cookie session provider
-type CookieProvider session.CookieProvider
-
-// SessionInit Init cookie session provider with max lifetime and config json.
-// maxlifetime is ignored.
-// json config:
-// securityKey - hash string
-// blockKey - gob encode hash string. it's saved as aes crypto.
-// securityName - recognized name in encoded cookie string
-// cookieName - cookie name
-// maxage - cookie max life time.
-func (pder *CookieProvider) SessionInit(maxlifetime int64, config string) error {
- return (*session.CookieProvider)(pder).SessionInit(context.Background(), maxlifetime, config)
-}
-
-// SessionRead Get SessionStore in cooke.
-// decode cooke string to map and put into SessionStore with sid.
-func (pder *CookieProvider) SessionRead(sid string) (Store, error) {
- s, err := (*session.CookieProvider)(pder).SessionRead(context.Background(), sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionExist Cookie session is always existed
-func (pder *CookieProvider) SessionExist(sid string) bool {
- res, _ := (*session.CookieProvider)(pder).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate Implement method, no used.
-func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (Store, error) {
- s, err := (*session.CookieProvider)(pder).SessionRegenerate(context.Background(), oldsid, sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionDestroy Implement method, no used.
-func (pder *CookieProvider) SessionDestroy(sid string) error {
- return (*session.CookieProvider)(pder).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Implement method, no used.
-func (pder *CookieProvider) SessionGC() {
- (*session.CookieProvider)(pder).SessionGC(context.Background())
-}
-
-// SessionAll Implement method, return 0.
-func (pder *CookieProvider) SessionAll() int {
- return (*session.CookieProvider)(pder).SessionAll(context.Background())
-}
-
-// SessionUpdate Implement method, no used.
-func (pder *CookieProvider) SessionUpdate(sid string) error {
- return (*session.CookieProvider)(pder).SessionUpdate(context.Background(), sid)
-}
diff --git a/adapter/session/sess_cookie_test.go b/adapter/session/sess_cookie_test.go
deleted file mode 100644
index 61937f56..00000000
--- a/adapter/session/sess_cookie_test.go
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "encoding/json"
- "net/http"
- "net/http/httptest"
- "strings"
- "testing"
-)
-
-const setCookieKey = "Set-Cookie"
-
-func TestCookie(t *testing.T) {
- config := `{"cookieName":"gosessionid","enableSetCookie":false,"gclifetime":3600,"ProviderConfig":"{\"cookieName\":\"gosessionid\",\"securityKey\":\"beegocookiehashkey\"}"}`
- conf := new(ManagerConfig)
- if err := json.Unmarshal([]byte(config), conf); err != nil {
- t.Fatal("json decode error", err)
- }
- globalSessions, err := NewManager("cookie", conf)
- if err != nil {
- t.Fatal("init cookie session err", err)
- }
- r, _ := http.NewRequest("GET", "/", nil)
- w := httptest.NewRecorder()
- sess, err := globalSessions.SessionStart(w, r)
- if err != nil {
- t.Fatal("set error,", err)
- }
- err = sess.Set("username", "astaxie")
- if err != nil {
- t.Fatal("set error,", err)
- }
- if username := sess.Get("username"); username != "astaxie" {
- t.Fatal("get username error")
- }
- sess.SessionRelease(w)
-
- if cookiestr := w.Header().Get(setCookieKey); cookiestr == "" {
- t.Fatal("setcookie error")
- } else {
- parts := strings.Split(strings.TrimSpace(cookiestr), ";")
- for k, v := range parts {
- nameval := strings.Split(v, "=")
- if k == 0 && nameval[0] != "gosessionid" {
- t.Fatal("error")
- }
- }
- }
-}
-
-func TestDestorySessionCookie(t *testing.T) {
- config := `{"cookieName":"gosessionid","enableSetCookie":true,"gclifetime":3600,"ProviderConfig":"{\"cookieName\":\"gosessionid\",\"securityKey\":\"beegocookiehashkey\"}"}`
- conf := new(ManagerConfig)
- if err := json.Unmarshal([]byte(config), conf); err != nil {
- t.Fatal("json decode error", err)
- }
- globalSessions, err := NewManager("cookie", conf)
- if err != nil {
- t.Fatal("init cookie session err", err)
- }
-
- r, _ := http.NewRequest("GET", "/", nil)
- w := httptest.NewRecorder()
- session, err := globalSessions.SessionStart(w, r)
- if err != nil {
- t.Fatal("session start err,", err)
- }
-
- // request again ,will get same sesssion id .
- r1, _ := http.NewRequest("GET", "/", nil)
- r1.Header.Set("Cookie", w.Header().Get(setCookieKey))
- w = httptest.NewRecorder()
- newSession, err := globalSessions.SessionStart(w, r1)
- if err != nil {
- t.Fatal("session start err,", err)
- }
- if newSession.SessionID() != session.SessionID() {
- t.Fatal("get cookie session id is not the same again.")
- }
-
- // After destroy session , will get a new session id .
- globalSessions.SessionDestroy(w, r1)
- r2, _ := http.NewRequest("GET", "/", nil)
- r2.Header.Set("Cookie", w.Header().Get(setCookieKey))
-
- w = httptest.NewRecorder()
- newSession, err = globalSessions.SessionStart(w, r2)
- if err != nil {
- t.Fatal("session start error")
- }
- if newSession.SessionID() == session.SessionID() {
- t.Fatal("after destroy session and reqeust again ,get cookie session id is same.")
- }
-}
diff --git a/adapter/session/sess_file.go b/adapter/session/sess_file.go
deleted file mode 100644
index c201cf74..00000000
--- a/adapter/session/sess_file.go
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-// FileSessionStore File session store
-type FileSessionStore session.FileSessionStore
-
-// Set value to file session
-func (fs *FileSessionStore) Set(key, value interface{}) error {
- return (*session.FileSessionStore)(fs).Set(context.Background(), key, value)
-}
-
-// Get value from file session
-func (fs *FileSessionStore) Get(key interface{}) interface{} {
- return (*session.FileSessionStore)(fs).Get(context.Background(), key)
-}
-
-// Delete value in file session by given key
-func (fs *FileSessionStore) Delete(key interface{}) error {
- return (*session.FileSessionStore)(fs).Delete(context.Background(), key)
-}
-
-// Flush Clean all values in file session
-func (fs *FileSessionStore) Flush() error {
- return (*session.FileSessionStore)(fs).Flush(context.Background())
-}
-
-// SessionID Get file session store id
-func (fs *FileSessionStore) SessionID() string {
- return (*session.FileSessionStore)(fs).SessionID(context.Background())
-}
-
-// SessionRelease Write file session to local file with Gob string
-func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) {
- (*session.FileSessionStore)(fs).SessionRelease(context.Background(), w)
-}
-
-// FileProvider File session provider
-type FileProvider session.FileProvider
-
-// SessionInit Init file session provider.
-// savePath sets the session files path.
-func (fp *FileProvider) SessionInit(maxlifetime int64, savePath string) error {
- return (*session.FileProvider)(fp).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead Read file session by sid.
-// if file is not exist, create it.
-// the file path is generated from sid string.
-func (fp *FileProvider) SessionRead(sid string) (Store, error) {
- s, err := (*session.FileProvider)(fp).SessionRead(context.Background(), sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionExist Check file session exist.
-// it checks the file named from sid exist or not.
-func (fp *FileProvider) SessionExist(sid string) bool {
- res, _ := (*session.FileProvider)(fp).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionDestroy Remove all files in this save path
-func (fp *FileProvider) SessionDestroy(sid string) error {
- return (*session.FileProvider)(fp).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC Recycle files in save path
-func (fp *FileProvider) SessionGC() {
- (*session.FileProvider)(fp).SessionGC(context.Background())
-}
-
-// SessionAll Get active file session number.
-// it walks save path to count files.
-func (fp *FileProvider) SessionAll() int {
- return (*session.FileProvider)(fp).SessionAll(context.Background())
-}
-
-// SessionRegenerate Generate new sid for file session.
-// it delete old file and create new file named from new sid.
-func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (Store, error) {
- s, err := (*session.FileProvider)(fp).SessionRegenerate(context.Background(), oldsid, sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
diff --git a/adapter/session/sess_file_test.go b/adapter/session/sess_file_test.go
deleted file mode 100644
index a3e3d0b9..00000000
--- a/adapter/session/sess_file_test.go
+++ /dev/null
@@ -1,336 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "fmt"
- "os"
- "sync"
- "testing"
- "time"
-)
-
-const (
- sid = "Session_id"
- sidNew = "Session_id_new"
- sessionPath = "./_session_runtime"
-)
-
-var mutex sync.Mutex
-
-func TestFileProviderSessionExist(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- if fp.SessionExist(sid) {
- t.Error()
- }
-
- _, err := fp.SessionRead(sid)
- if err != nil {
- t.Error(err)
- }
-
- if !fp.SessionExist(sid) {
- t.Error()
- }
-}
-
-func TestFileProviderSessionExist2(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- if fp.SessionExist(sid) {
- t.Error()
- }
-
- if fp.SessionExist("") {
- t.Error()
- }
-
- if fp.SessionExist("1") {
- t.Error()
- }
-}
-
-func TestFileProviderSessionRead(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- s, err := fp.SessionRead(sid)
- if err != nil {
- t.Error(err)
- }
-
- _ = s.Set("sessionValue", 18975)
- v := s.Get("sessionValue")
-
- if v.(int) != 18975 {
- t.Error()
- }
-}
-
-func TestFileProviderSessionRead1(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- _, err := fp.SessionRead("")
- if err == nil {
- t.Error(err)
- }
-
- _, err = fp.SessionRead("1")
- if err == nil {
- t.Error(err)
- }
-}
-
-func TestFileProviderSessionAll(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- sessionCount := 546
-
- for i := 1; i <= sessionCount; i++ {
- _, err := fp.SessionRead(fmt.Sprintf("%s_%d", sid, i))
- if err != nil {
- t.Error(err)
- }
- }
-
- if fp.SessionAll() != sessionCount {
- t.Error()
- }
-}
-
-func TestFileProviderSessionRegenerate(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- _, err := fp.SessionRead(sid)
- if err != nil {
- t.Error(err)
- }
-
- if !fp.SessionExist(sid) {
- t.Error()
- }
-
- _, err = fp.SessionRegenerate(sid, sidNew)
- if err != nil {
- t.Error(err)
- }
-
- if fp.SessionExist(sid) {
- t.Error()
- }
-
- if !fp.SessionExist(sidNew) {
- t.Error()
- }
-}
-
-func TestFileProviderSessionDestroy(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- _, err := fp.SessionRead(sid)
- if err != nil {
- t.Error(err)
- }
-
- if !fp.SessionExist(sid) {
- t.Error()
- }
-
- err = fp.SessionDestroy(sid)
- if err != nil {
- t.Error(err)
- }
-
- if fp.SessionExist(sid) {
- t.Error()
- }
-}
-
-func TestFileProviderSessionGC(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(1, sessionPath)
-
- sessionCount := 412
-
- for i := 1; i <= sessionCount; i++ {
- _, err := fp.SessionRead(fmt.Sprintf("%s_%d", sid, i))
- if err != nil {
- t.Error(err)
- }
- }
-
- time.Sleep(2 * time.Second)
-
- fp.SessionGC()
- if fp.SessionAll() != 0 {
- t.Error()
- }
-}
-
-func TestFileSessionStoreSet(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- sessionCount := 100
- s, _ := fp.SessionRead(sid)
- for i := 1; i <= sessionCount; i++ {
- err := s.Set(i, i)
- if err != nil {
- t.Error(err)
- }
- }
-}
-
-func TestFileSessionStoreGet(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- sessionCount := 100
- s, _ := fp.SessionRead(sid)
- for i := 1; i <= sessionCount; i++ {
- _ = s.Set(i, i)
-
- v := s.Get(i)
- if v.(int) != i {
- t.Error()
- }
- }
-}
-
-func TestFileSessionStoreDelete(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- s, _ := fp.SessionRead(sid)
- s.Set("1", 1)
-
- if s.Get("1") == nil {
- t.Error()
- }
-
- s.Delete("1")
-
- if s.Get("1") != nil {
- t.Error()
- }
-}
-
-func TestFileSessionStoreFlush(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- sessionCount := 100
- s, _ := fp.SessionRead(sid)
- for i := 1; i <= sessionCount; i++ {
- _ = s.Set(i, i)
- }
-
- _ = s.Flush()
-
- for i := 1; i <= sessionCount; i++ {
- if s.Get(i) != nil {
- t.Error()
- }
- }
-}
-
-func TestFileSessionStoreSessionID(t *testing.T) {
- mutex.Lock()
- defer mutex.Unlock()
- os.RemoveAll(sessionPath)
- defer os.RemoveAll(sessionPath)
- fp := &FileProvider{}
-
- _ = fp.SessionInit(180, sessionPath)
-
- sessionCount := 85
-
- for i := 1; i <= sessionCount; i++ {
- s, err := fp.SessionRead(fmt.Sprintf("%s_%d", sid, i))
- if err != nil {
- t.Error(err)
- }
- if s.SessionID() != fmt.Sprintf("%s_%d", sid, i) {
- t.Error(err)
- }
- }
-}
diff --git a/adapter/session/sess_mem.go b/adapter/session/sess_mem.go
deleted file mode 100644
index 6a4e62c6..00000000
--- a/adapter/session/sess_mem.go
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-// MemSessionStore memory session store.
-// it saved sessions in a map in memory.
-type MemSessionStore session.MemSessionStore
-
-// Set value to memory session
-func (st *MemSessionStore) Set(key, value interface{}) error {
- return (*session.MemSessionStore)(st).Set(context.Background(), key, value)
-}
-
-// Get value from memory session by key
-func (st *MemSessionStore) Get(key interface{}) interface{} {
- return (*session.MemSessionStore)(st).Get(context.Background(), key)
-}
-
-// Delete in memory session by key
-func (st *MemSessionStore) Delete(key interface{}) error {
- return (*session.MemSessionStore)(st).Delete(context.Background(), key)
-}
-
-// Flush clear all values in memory session
-func (st *MemSessionStore) Flush() error {
- return (*session.MemSessionStore)(st).Flush(context.Background())
-}
-
-// SessionID get this id of memory session store
-func (st *MemSessionStore) SessionID() string {
- return (*session.MemSessionStore)(st).SessionID(context.Background())
-}
-
-// SessionRelease Implement method, no used.
-func (st *MemSessionStore) SessionRelease(w http.ResponseWriter) {
- (*session.MemSessionStore)(st).SessionRelease(context.Background(), w)
-}
-
-// MemProvider Implement the provider interface
-type MemProvider session.MemProvider
-
-// SessionInit init memory session
-func (pder *MemProvider) SessionInit(maxlifetime int64, savePath string) error {
- return (*session.MemProvider)(pder).SessionInit(context.Background(), maxlifetime, savePath)
-}
-
-// SessionRead get memory session store by sid
-func (pder *MemProvider) SessionRead(sid string) (Store, error) {
- s, err := (*session.MemProvider)(pder).SessionRead(context.Background(), sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionExist check session store exist in memory session by sid
-func (pder *MemProvider) SessionExist(sid string) bool {
- res, _ := (*session.MemProvider)(pder).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate generate new sid for session store in memory session
-func (pder *MemProvider) SessionRegenerate(oldsid, sid string) (Store, error) {
- s, err := (*session.MemProvider)(pder).SessionRegenerate(context.Background(), oldsid, sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionDestroy delete session store in memory session by id
-func (pder *MemProvider) SessionDestroy(sid string) error {
- return (*session.MemProvider)(pder).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC clean expired session stores in memory session
-func (pder *MemProvider) SessionGC() {
- (*session.MemProvider)(pder).SessionGC(context.Background())
-}
-
-// SessionAll get count number of memory session
-func (pder *MemProvider) SessionAll() int {
- return (*session.MemProvider)(pder).SessionAll(context.Background())
-}
-
-// SessionUpdate expand time of session store by id in memory session
-func (pder *MemProvider) SessionUpdate(sid string) error {
- return (*session.MemProvider)(pder).SessionUpdate(context.Background(), sid)
-}
diff --git a/adapter/session/sess_mem_test.go b/adapter/session/sess_mem_test.go
deleted file mode 100644
index 2e8934b8..00000000
--- a/adapter/session/sess_mem_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "encoding/json"
- "net/http"
- "net/http/httptest"
- "strings"
- "testing"
-)
-
-func TestMem(t *testing.T) {
- config := `{"cookieName":"gosessionid","gclifetime":10, "enableSetCookie":true}`
- conf := new(ManagerConfig)
- if err := json.Unmarshal([]byte(config), conf); err != nil {
- t.Fatal("json decode error", err)
- }
- globalSessions, _ := NewManager("memory", conf)
- go globalSessions.GC()
- r, _ := http.NewRequest("GET", "/", nil)
- w := httptest.NewRecorder()
- sess, err := globalSessions.SessionStart(w, r)
- if err != nil {
- t.Fatal("set error,", err)
- }
- defer sess.SessionRelease(w)
- err = sess.Set("username", "astaxie")
- if err != nil {
- t.Fatal("set error,", err)
- }
- if username := sess.Get("username"); username != "astaxie" {
- t.Fatal("get username error")
- }
- if cookiestr := w.Header().Get("Set-Cookie"); cookiestr == "" {
- t.Fatal("setcookie error")
- } else {
- parts := strings.Split(strings.TrimSpace(cookiestr), ";")
- for k, v := range parts {
- nameval := strings.Split(v, "=")
- if k == 0 && nameval[0] != "gosessionid" {
- t.Fatal("error")
- }
- }
- }
-}
diff --git a/adapter/session/sess_test.go b/adapter/session/sess_test.go
deleted file mode 100644
index 2ecd2dd9..00000000
--- a/adapter/session/sess_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "testing"
-)
-
-func TestGob(t *testing.T) {
- a := make(map[interface{}]interface{})
- a["username"] = "astaxie"
- a[12] = 234
- a["user"] = User{"asta", "xie"}
- b, err := EncodeGob(a)
- if err != nil {
- t.Error(err)
- }
- c, err := DecodeGob(b)
- if err != nil {
- t.Error(err)
- }
- if len(c) == 0 {
- t.Error("decodeGob empty")
- }
- if c["username"] != "astaxie" {
- t.Error("decode string error")
- }
- if c[12] != 234 {
- t.Error("decode int error")
- }
- if c["user"].(User).Username != "asta" {
- t.Error("decode struct error")
- }
-}
-
-type User struct {
- Username string
- NickName string
-}
diff --git a/adapter/session/sess_utils.go b/adapter/session/sess_utils.go
deleted file mode 100644
index 2fe229d7..00000000
--- a/adapter/session/sess_utils.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session
-
-import (
- "github.com/beego/beego/v2/server/web/session"
-)
-
-// EncodeGob encode the obj to gob
-func EncodeGob(obj map[interface{}]interface{}) ([]byte, error) {
- return session.EncodeGob(obj)
-}
-
-// DecodeGob decode data to map
-func DecodeGob(encoded []byte) (map[interface{}]interface{}, error) {
- return session.DecodeGob(encoded)
-}
diff --git a/adapter/session/session.go b/adapter/session/session.go
deleted file mode 100644
index 256bd601..00000000
--- a/adapter/session/session.go
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 session provider
-//
-// Usage:
-// import(
-// "github.com/beego/beego/v2/server/web/session"
-// )
-//
-// func init() {
-// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`)
-// go globalSessions.GC()
-// }
-//
-package session
-
-import (
- "io"
- "net/http"
- "os"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-// Store contains all data for one session process with specific id.
-type Store interface {
- Set(key, value interface{}) error // set session value
- Get(key interface{}) interface{} // get session value
- Delete(key interface{}) error // delete session value
- SessionID() string // back current sessionID
- SessionRelease(w http.ResponseWriter) // release the resource & save data to provider & return the data
- Flush() error // delete all data
-}
-
-// Provider contains global session methods and saved SessionStores.
-// it can operate a SessionStore by its id.
-type Provider interface {
- SessionInit(gclifetime int64, config string) error
- SessionRead(sid string) (Store, error)
- SessionExist(sid string) bool
- SessionRegenerate(oldsid, sid string) (Store, error)
- SessionDestroy(sid string) error
- SessionAll() int // get all active session
- SessionGC()
-}
-
-// SLogger a helpful variable to log information about session
-var SLogger = NewSessionLog(os.Stderr)
-
-// Register makes a session provide available by the provided name.
-// If Register is called twice with the same name or if driver is nil,
-// it panics.
-func Register(name string, provide Provider) {
- session.Register(name, &oldToNewProviderAdapter{
- delegate: provide,
- })
-}
-
-// GetProvider
-func GetProvider(name string) (Provider, error) {
- res, err := session.GetProvider(name)
- if adt, ok := res.(*oldToNewProviderAdapter); err == nil && ok {
- return adt.delegate, err
- }
-
- return &newToOldProviderAdapter{
- delegate: res,
- }, err
-}
-
-// ManagerConfig define the session config
-type ManagerConfig session.ManagerConfig
-
-// Manager contains Provider and its configuration.
-type Manager session.Manager
-
-// NewManager Create new Manager with provider name and json config string.
-// provider name:
-// 1. cookie
-// 2. file
-// 3. memory
-// 4. redis
-// 5. mysql
-// json config:
-// 1. is https default false
-// 2. hashfunc default sha1
-// 3. hashkey default beegosessionkey
-// 4. maxage default is none
-func NewManager(provideName string, cf *ManagerConfig) (*Manager, error) {
- m, err := session.NewManager(provideName, (*session.ManagerConfig)(cf))
- return (*Manager)(m), err
-}
-
-// GetProvider return current manager's provider
-func (manager *Manager) GetProvider() Provider {
- return &newToOldProviderAdapter{
- delegate: (*session.Manager)(manager).GetProvider(),
- }
-}
-
-// SessionStart generate or read the session id from http request.
-// if session id exists, return SessionStore with this id.
-func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (Store, error) {
- s, err := (*session.Manager)(manager).SessionStart(w, r)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// SessionDestroy Destroy session by its id in http request cookie.
-func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request) {
- (*session.Manager)(manager).SessionDestroy(w, r)
-}
-
-// GetSessionStore Get SessionStore by its id.
-func (manager *Manager) GetSessionStore(sid string) (Store, error) {
- s, err := (*session.Manager)(manager).GetSessionStore(sid)
- return &NewToOldStoreAdapter{
- delegate: s,
- }, err
-}
-
-// GC Start session gc process.
-// it can do gc in times after gc lifetime.
-func (manager *Manager) GC() {
- (*session.Manager)(manager).GC()
-}
-
-// SessionRegenerateID Regenerate a session id for this SessionStore who's id is saving in http request.
-func (manager *Manager) SessionRegenerateID(w http.ResponseWriter, r *http.Request) Store {
- s, _ := (*session.Manager)(manager).SessionRegenerateID(w, r)
- return &NewToOldStoreAdapter{
- delegate: s,
- }
-}
-
-// GetActiveSession Get all active sessions count number.
-func (manager *Manager) GetActiveSession() int {
- return (*session.Manager)(manager).GetActiveSession()
-}
-
-// SetSecure Set cookie with https.
-func (manager *Manager) SetSecure(secure bool) {
- (*session.Manager)(manager).SetSecure(secure)
-}
-
-// Log implement the log.Logger
-type Log session.Log
-
-// NewSessionLog set io.Writer to create a Logger for session.
-func NewSessionLog(out io.Writer) *Log {
- return (*Log)(session.NewSessionLog(out))
-}
diff --git a/adapter/session/ssdb/sess_ssdb.go b/adapter/session/ssdb/sess_ssdb.go
deleted file mode 100644
index 9d08b2ab..00000000
--- a/adapter/session/ssdb/sess_ssdb.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package ssdb
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/adapter/session"
- beeSsdb "github.com/beego/beego/v2/server/web/session/ssdb"
-)
-
-// Provider holds ssdb client and configs
-type Provider beeSsdb.Provider
-
-// SessionInit init the ssdb with the config
-func (p *Provider) SessionInit(maxLifetime int64, savePath string) error {
- return (*beeSsdb.Provider)(p).SessionInit(context.Background(), maxLifetime, savePath)
-}
-
-// SessionRead return a ssdb client session Store
-func (p *Provider) SessionRead(sid string) (session.Store, error) {
- s, err := (*beeSsdb.Provider)(p).SessionRead(context.Background(), sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionExist judged whether sid is exist in session
-func (p *Provider) SessionExist(sid string) bool {
- res, _ := (*beeSsdb.Provider)(p).SessionExist(context.Background(), sid)
- return res
-}
-
-// SessionRegenerate regenerate session with new sid and delete oldsid
-func (p *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
- s, err := (*beeSsdb.Provider)(p).SessionRegenerate(context.Background(), oldsid, sid)
- return session.CreateNewToOldStoreAdapter(s), err
-}
-
-// SessionDestroy destroy the sid
-func (p *Provider) SessionDestroy(sid string) error {
- return (*beeSsdb.Provider)(p).SessionDestroy(context.Background(), sid)
-}
-
-// SessionGC not implemented
-func (p *Provider) SessionGC() {
- (*beeSsdb.Provider)(p).SessionGC(context.Background())
-}
-
-// SessionAll not implemented
-func (p *Provider) SessionAll() int {
- return (*beeSsdb.Provider)(p).SessionAll(context.Background())
-}
-
-// SessionStore holds the session information which stored in ssdb
-type SessionStore beeSsdb.SessionStore
-
-// Set the key and value
-func (s *SessionStore) Set(key, value interface{}) error {
- return (*beeSsdb.SessionStore)(s).Set(context.Background(), key, value)
-}
-
-// Get return the value by the key
-func (s *SessionStore) Get(key interface{}) interface{} {
- return (*beeSsdb.SessionStore)(s).Get(context.Background(), key)
-}
-
-// Delete the key in session store
-func (s *SessionStore) Delete(key interface{}) error {
- return (*beeSsdb.SessionStore)(s).Delete(context.Background(), key)
-}
-
-// Flush delete all keys and values
-func (s *SessionStore) Flush() error {
- return (*beeSsdb.SessionStore)(s).Flush(context.Background())
-}
-
-// SessionID return the sessionID
-func (s *SessionStore) SessionID() string {
- return (*beeSsdb.SessionStore)(s).SessionID(context.Background())
-}
-
-// SessionRelease Store the keyvalues into ssdb
-func (s *SessionStore) SessionRelease(w http.ResponseWriter) {
- (*beeSsdb.SessionStore)(s).SessionRelease(context.Background(), w)
-}
diff --git a/adapter/session/store_adapter.go b/adapter/session/store_adapter.go
deleted file mode 100644
index a459e68c..00000000
--- a/adapter/session/store_adapter.go
+++ /dev/null
@@ -1,84 +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 session
-
-import (
- "context"
- "net/http"
-
- "github.com/beego/beego/v2/server/web/session"
-)
-
-type NewToOldStoreAdapter struct {
- delegate session.Store
-}
-
-func CreateNewToOldStoreAdapter(s session.Store) Store {
- return &NewToOldStoreAdapter{
- delegate: s,
- }
-}
-
-func (n *NewToOldStoreAdapter) Set(key, value interface{}) error {
- return n.delegate.Set(context.Background(), key, value)
-}
-
-func (n *NewToOldStoreAdapter) Get(key interface{}) interface{} {
- return n.delegate.Get(context.Background(), key)
-}
-
-func (n *NewToOldStoreAdapter) Delete(key interface{}) error {
- return n.delegate.Delete(context.Background(), key)
-}
-
-func (n *NewToOldStoreAdapter) SessionID() string {
- return n.delegate.SessionID(context.Background())
-}
-
-func (n *NewToOldStoreAdapter) SessionRelease(w http.ResponseWriter) {
- n.delegate.SessionRelease(context.Background(), w)
-}
-
-func (n *NewToOldStoreAdapter) Flush() error {
- return n.delegate.Flush(context.Background())
-}
-
-type oldToNewStoreAdapter struct {
- delegate Store
-}
-
-func (o *oldToNewStoreAdapter) Set(ctx context.Context, key, value interface{}) error {
- return o.delegate.Set(key, value)
-}
-
-func (o *oldToNewStoreAdapter) Get(ctx context.Context, key interface{}) interface{} {
- return o.delegate.Get(key)
-}
-
-func (o *oldToNewStoreAdapter) Delete(ctx context.Context, key interface{}) error {
- return o.delegate.Delete(key)
-}
-
-func (o *oldToNewStoreAdapter) SessionID(ctx context.Context) string {
- return o.delegate.SessionID()
-}
-
-func (o *oldToNewStoreAdapter) SessionRelease(ctx context.Context, w http.ResponseWriter) {
- o.delegate.SessionRelease(w)
-}
-
-func (o *oldToNewStoreAdapter) Flush(ctx context.Context) error {
- return o.delegate.Flush()
-}
diff --git a/adapter/swagger/swagger.go b/adapter/swagger/swagger.go
deleted file mode 100644
index fbb00bb4..00000000
--- a/adapter/swagger/swagger.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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.
-//
-// Swagger™ is a project used to describe and document RESTful APIs.
-//
-// The Swagger specification defines a set of files required to describe such an API. These files can then be used by the Swagger-UI project to display the API and Swagger-Codegen to generate clients in various languages. Additional utilities can also take advantage of the resulting files, such as testing tools.
-// Now in version 2.0, Swagger is more enabling than ever. And it's 100% open source software.
-
-// Package swagger struct definition
-package swagger
-
-import (
- "github.com/beego/beego/v2/server/web/swagger"
-)
-
-// Swagger list the resource
-type Swagger swagger.Swagger
-
-// Information Provides metadata about the API. The metadata can be used by the clients if needed.
-type Information swagger.Information
-
-// Contact information for the exposed API.
-type Contact swagger.Contact
-
-// License information for the exposed API.
-type License swagger.License
-
-// Item Describes the operations available on a single path.
-type Item swagger.Item
-
-// Operation Describes a single API operation on a path.
-type Operation swagger.Operation
-
-// Parameter Describes a single operation parameter.
-type Parameter swagger.Parameter
-
-// ParameterItems A limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body".
-// http://swagger.io/specification/#itemsObject
-type ParameterItems swagger.ParameterItems
-
-// Schema Object allows the definition of input and output data types.
-type Schema swagger.Schema
-
-// Propertie are taken from the JSON Schema definition but their definitions were adjusted to the Swagger Specification
-type Propertie swagger.Propertie
-
-// Response as they are returned from executing this operation.
-type Response swagger.Response
-
-// Security Allows the definition of a security scheme that can be used by the operations
-type Security swagger.Security
-
-// Tag Allows adding meta data to a single tag that is used by the Operation Object
-type Tag swagger.Tag
-
-// ExternalDocs include Additional external documentation
-type ExternalDocs swagger.ExternalDocs
diff --git a/adapter/template.go b/adapter/template.go
deleted file mode 100644
index 5957a0eb..00000000
--- a/adapter/template.go
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "html/template"
- "io"
- "net/http"
-
- "github.com/beego/beego/v2/server/web"
-)
-
-// ExecuteTemplate applies the template with name to the specified data object,
-// writing the output to wr.
-// A template will be executed safely in parallel.
-func ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
- return web.ExecuteTemplate(wr, name, data)
-}
-
-// ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object,
-// writing the output to wr.
-// A template will be executed safely in parallel.
-func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data interface{}) error {
- return web.ExecuteViewPathTemplate(wr, name, viewPath, data)
-}
-
-// AddFuncMap let user to register a func in the template.
-func AddFuncMap(key string, fn interface{}) error {
- return web.AddFuncMap(key, fn)
-}
-
-type templatePreProcessor func(root, path string, funcs template.FuncMap) (*template.Template, error)
-
-type templateFile struct {
- root string
- files map[string][]string
-}
-
-// HasTemplateExt return this path contains supported template extension of beego or not.
-func HasTemplateExt(paths string) bool {
- return web.HasTemplateExt(paths)
-}
-
-// AddTemplateExt add new extension for template.
-func AddTemplateExt(ext string) {
- web.AddTemplateExt(ext)
-}
-
-// AddViewPath adds a new path to the supported view paths.
-// Can later be used by setting a controller ViewPath to this folder
-// will panic if called after beego.Run()
-func AddViewPath(viewPath string) error {
- return web.AddViewPath(viewPath)
-}
-
-// BuildTemplate will build all template files in a directory.
-// it makes beego can render any template file in view directory.
-func BuildTemplate(dir string, files ...string) error {
- return web.BuildTemplate(dir, files...)
-}
-
-type templateFSFunc func() http.FileSystem
-
-func defaultFSFunc() http.FileSystem {
- return FileSystem{}
-}
-
-// SetTemplateFSFunc set default filesystem function
-func SetTemplateFSFunc(fnt templateFSFunc) {
- web.SetTemplateFSFunc(func() http.FileSystem {
- return fnt()
- })
-}
-
-// SetViewsPath sets view directory path in beego application.
-func SetViewsPath(path string) *App {
- return (*App)(web.SetViewsPath(path))
-}
-
-// SetStaticPath sets static directory path and proper url pattern in beego application.
-// if beego.SetStaticPath("static","public"), visit /static/* to load static file in folder "public".
-func SetStaticPath(url string, path string) *App {
- return (*App)(web.SetStaticPath(url, path))
-}
-
-// DelStaticPath removes the static folder setting in this url pattern in beego application.
-func DelStaticPath(url string) *App {
- return (*App)(web.DelStaticPath(url))
-}
-
-// AddTemplateEngine add a new templatePreProcessor which support extension
-func AddTemplateEngine(extension string, fn templatePreProcessor) *App {
- return (*App)(web.AddTemplateEngine(extension, func(root, path string, funcs template.FuncMap) (*template.Template, error) {
- return fn(root, path, funcs)
- }))
-}
diff --git a/adapter/templatefunc.go b/adapter/templatefunc.go
deleted file mode 100644
index 32a250d1..00000000
--- a/adapter/templatefunc.go
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "html/template"
- "net/url"
- "time"
-
- "github.com/beego/beego/v2/server/web"
-)
-
-const (
- formatTime = "15:04:05"
- formatDate = "2006-01-02"
- formatDateTime = "2006-01-02 15:04:05"
- formatDateTimeT = "2006-01-02T15:04:05"
-)
-
-// Substr returns the substr from start to length.
-func Substr(s string, start, length int) string {
- return web.Substr(s, start, length)
-}
-
-// HTML2str returns escaping text convert from html.
-func HTML2str(html string) string {
- return web.HTML2str(html)
-}
-
-// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
-func DateFormat(t time.Time, layout string) (datestring string) {
- return web.DateFormat(t, layout)
-}
-
-// DateParse Parse Date use PHP time format.
-func DateParse(dateString, format string) (time.Time, error) {
- return web.DateParse(dateString, format)
-}
-
-// Date takes a PHP like date func to Go's time format.
-func Date(t time.Time, format string) string {
- return web.Date(t, format)
-}
-
-// Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal.
-// Whitespace is trimmed. Used by the template parser as "eq".
-func Compare(a, b interface{}) (equal bool) {
- return web.Compare(a, b)
-}
-
-// CompareNot !Compare
-func CompareNot(a, b interface{}) (equal bool) {
- return web.CompareNot(a, b)
-}
-
-// NotNil the same as CompareNot
-func NotNil(a interface{}) (isNil bool) {
- return web.NotNil(a)
-}
-
-// GetConfig get the Appconfig
-func GetConfig(returnType, key string, defaultVal interface{}) (interface{}, error) {
- return web.GetConfig(returnType, key, defaultVal)
-}
-
-// Str2html Convert string to template.HTML type.
-func Str2html(raw string) template.HTML {
- return web.Str2html(raw)
-}
-
-// Htmlquote returns quoted html string.
-func Htmlquote(text string) string {
- return web.Htmlquote(text)
-}
-
-// Htmlunquote returns unquoted html string.
-func Htmlunquote(text string) string {
- return web.Htmlunquote(text)
-}
-
-// URLFor returns url string with another registered controller handler with params.
-// usage:
-//
-// URLFor(".index")
-// print URLFor("index")
-// router /login
-// print URLFor("login")
-// print URLFor("login", "next","/"")
-// router /profile/:username
-// print UrlFor("profile", ":username","John Doe")
-// result:
-// /
-// /login
-// /login?next=/
-// /user/John%20Doe
-//
-func URLFor(endpoint string, values ...interface{}) string {
- return web.URLFor(endpoint, values...)
-}
-
-// AssetsJs returns script tag with src string.
-func AssetsJs(text string) template.HTML {
- return web.AssetsJs(text)
-}
-
-// AssetsCSS returns stylesheet link tag with src string.
-func AssetsCSS(text string) template.HTML {
- text = ""
-
- return template.HTML(text)
-}
-
-// ParseForm will parse form values to struct via tag.
-func ParseForm(form url.Values, obj interface{}) error {
- return web.ParseForm(form, obj)
-}
-
-// RenderForm will render object to form html.
-// obj must be a struct pointer.
-func RenderForm(obj interface{}) template.HTML {
- return web.RenderForm(obj)
-}
-
-// MapGet getting value from map by keys
-// usage:
-// Data["m"] = M{
-// "a": 1,
-// "1": map[string]float64{
-// "c": 4,
-// },
-// }
-//
-// {{ map_get m "a" }} // return 1
-// {{ map_get m 1 "c" }} // return 4
-func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) {
- return web.MapGet(arg1, arg2...)
-}
diff --git a/adapter/templatefunc_test.go b/adapter/templatefunc_test.go
deleted file mode 100644
index b3d5e968..00000000
--- a/adapter/templatefunc_test.go
+++ /dev/null
@@ -1,236 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "html/template"
- "net/url"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestSubstr(t *testing.T) {
- s := `012345`
- assert.Equal(t, "01", Substr(s, 0, 2))
- assert.Equal(t, "012345", Substr(s, 0, 100))
- assert.Equal(t, "012345", Substr(s, 12, 100))
-}
-
-func TestHtml2str(t *testing.T) {
- h := `<123> 123\n
-
-
- \n`
- assert.Equal(t, "123\\n\n\\n", HTML2str(h))
-}
-
-func TestDateFormat(t *testing.T) {
- ts := "Mon, 01 Jul 2013 13:27:42 CST"
- tt, _ := time.Parse(time.RFC1123, ts)
-
- assert.Equal(t, "2013-07-01 13:27:42", DateFormat(tt, "2006-01-02 15:04:05"))
-}
-
-func TestDate(t *testing.T) {
- ts := "Mon, 01 Jul 2013 13:27:42 CST"
- tt, _ := time.Parse(time.RFC1123, ts)
-
- assert.Equal(t, "2013-07-01 13:27:42", Date(tt, "Y-m-d H:i:s"))
-
- assert.Equal(t, "13-7-1 01:27:42 PM", Date(tt, "y-n-j h:i:s A"))
- assert.Equal(t, "Mon, 01 Jul 2013 1:27:42 pm", Date(tt, "D, d M Y g:i:s a"))
- assert.Equal(t, "Monday, 01 July 2013 13:27:42", Date(tt, "l, d F Y G:i:s"))
-}
-
-func TestCompareRelated(t *testing.T) {
- assert.True(t, Compare("abc", "abc"))
-
- assert.False(t, Compare("abc", "aBc"))
-
- assert.True(t, Compare("1", 1))
-
- assert.False(t, CompareNot("abc", "abc"))
-
- assert.True(t, CompareNot("abc", "aBc"))
- assert.True(t, NotNil("a string"))
-}
-
-func TestHtmlquote(t *testing.T) {
- h := `<' ”“&">`
- s := `<' ”“&">`
- assert.Equal(t, h, Htmlquote(s))
-}
-
-func TestHtmlunquote(t *testing.T) {
- h := `<' ”“&">`
- s := `<' ”“&">`
- assert.Equal(t, s, Htmlunquote(h))
-}
-
-func TestParseForm(t *testing.T) {
- type ExtendInfo struct {
- Hobby []string `form:"hobby"`
- Memo string
- }
-
- type OtherInfo struct {
- Organization string `form:"organization"`
- Title string `form:"title"`
- ExtendInfo
- }
-
- type user struct {
- ID int `form:"-"`
- tag string `form:"tag"`
- Name interface{} `form:"username"`
- Age int `form:"age,text"`
- Email string
- Intro string `form:",textarea"`
- StrBool bool `form:"strbool"`
- Date time.Time `form:"date,2006-01-02"`
- OtherInfo
- }
-
- u := user{}
- form := url.Values{
- "ID": []string{"1"},
- "-": []string{"1"},
- "tag": []string{"no"},
- "username": []string{"test"},
- "age": []string{"40"},
- "Email": []string{"test@gmail.com"},
- "Intro": []string{"I am an engineer!"},
- "strbool": []string{"yes"},
- "date": []string{"2014-11-12"},
- "organization": []string{"beego"},
- "title": []string{"CXO"},
- "hobby": []string{"", "Basketball", "Football"},
- "memo": []string{"nothing"},
- }
-
- assert.NotNil(t, ParseForm(form, u))
-
- assert.Nil(t, ParseForm(form, &u))
-
- assert.Equal(t, 0, u.ID)
-
- assert.Equal(t, 0, len(u.tag))
-
- assert.Equal(t, "test", u.Name)
-
- assert.Equal(t, 40, u.Age)
-
- assert.Equal(t, "test@gmail.com", u.Email)
-
- assert.Equal(t, "I am an engineer!", u.Intro)
-
- assert.True(t, u.StrBool)
-
- y, m, d := u.Date.Date()
-
- assert.Equal(t, 2014, y)
- assert.Equal(t, "November", m.String())
- assert.Equal(t, 12, d)
-
- assert.Equal(t, "beego", u.Organization)
-
- assert.Equal(t, "CXO", u.Title)
-
- assert.Equal(t, "", u.Hobby[0])
-
- assert.Equal(t, "Basketball", u.Hobby[1])
-
- assert.Equal(t, "Football", u.Hobby[2])
-
- assert.Equal(t, 0, len(u.Memo))
-}
-
-func TestRenderForm(t *testing.T) {
- type user struct {
- ID int `form:"-"`
- Name interface{} `form:"username"`
- Age int `form:"age,text,年龄:"`
- Sex string
- Email []string
- Intro string `form:",textarea"`
- Ignored string `form:"-"`
- }
-
- u := user{Name: "test", Intro: "Some Text"}
- output := RenderForm(u)
- assert.Equal(t, template.HTML(""), output)
- output = RenderForm(&u)
- result := template.HTML(
- `Name: ` +
- `年龄:` +
- `Sex: ` +
- `Intro: `)
- assert.Equal(t, result, output)
-}
-
-func TestMapGet(t *testing.T) {
- // test one level map
- m1 := map[string]int64{
- "a": 1,
- "1": 2,
- }
-
- res, err := MapGet(m1, "a")
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res)
-
- res, err = MapGet(m1, "1")
- 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)
-
- // test 2 level map
- m2 := M{
- "1": map[string]float64{
- "2": 3.5,
- },
- }
-
- res, err = MapGet(m2, 1, 2)
- assert.Nil(t, err)
- assert.Equal(t, 3.5, res)
-
- // test 5 level map
- m5 := M{
- "1": M{
- "2": M{
- "3": M{
- "4": M{
- "5": 1.2,
- },
- },
- },
- },
- }
-
- res, err = MapGet(m5, 1, 2, 3, 4, 5)
- assert.Nil(t, err)
- assert.Equal(t, 1.2, res)
-
- // check whether element not exists in map
- res, err = MapGet(m5, 5, 4, 3, 2, 1)
- assert.Nil(t, err)
- assert.Nil(t, res)
-}
diff --git a/adapter/testing/client.go b/adapter/testing/client.go
deleted file mode 100644
index a773c9a6..00000000
--- a/adapter/testing/client.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 testing
-
-import "github.com/beego/beego/v2/client/httplib/testing"
-
-// TestHTTPRequest beego test request client
-type TestHTTPRequest testing.TestHTTPRequest
-
-// Get returns test client in GET method
-func Get(path string) *TestHTTPRequest {
- return (*TestHTTPRequest)(testing.Get(path))
-}
-
-// Post returns test client in POST method
-func Post(path string) *TestHTTPRequest {
- return (*TestHTTPRequest)(testing.Post(path))
-}
-
-// Put returns test client in PUT method
-func Put(path string) *TestHTTPRequest {
- return (*TestHTTPRequest)(testing.Put(path))
-}
-
-// Delete returns test client in DELETE method
-func Delete(path string) *TestHTTPRequest {
- return (*TestHTTPRequest)(testing.Delete(path))
-}
-
-// Head returns test client in HEAD method
-func Head(path string) *TestHTTPRequest {
- return (*TestHTTPRequest)(testing.Head(path))
-}
diff --git a/adapter/toolbox/healthcheck.go b/adapter/toolbox/healthcheck.go
deleted file mode 100644
index 400e707e..00000000
--- a/adapter/toolbox/healthcheck.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox healthcheck
-//
-// type DatabaseCheck struct {
-// }
-//
-// func (dc *DatabaseCheck) Check() error {
-// if dc.isConnected() {
-// return nil
-// } else {
-// return errors.New("can't connect database")
-// }
-// }
-//
-// AddHealthCheck("database",&DatabaseCheck{})
-//
-package toolbox
-
-import (
- "github.com/beego/beego/v2/core/admin"
-)
-
-// AdminCheckList holds health checker map
-// Deprecated using admin.AdminCheckList
-var AdminCheckList map[string]HealthChecker
-
-// HealthChecker health checker interface
-type HealthChecker admin.HealthChecker
-
-// AddHealthCheck add health checker with name string
-func AddHealthCheck(name string, hc HealthChecker) {
- admin.AddHealthCheck(name, hc)
- AdminCheckList[name] = hc
-}
-
-func init() {
- AdminCheckList = make(map[string]HealthChecker)
-}
diff --git a/adapter/toolbox/profile.go b/adapter/toolbox/profile.go
deleted file mode 100644
index 00b0eef7..00000000
--- a/adapter/toolbox/profile.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox
-
-import (
- "io"
-
- "github.com/beego/beego/v2/core/admin"
-)
-
-// ProcessInput parse input command string
-func ProcessInput(input string, w io.Writer) {
- admin.ProcessInput(input, w)
-}
-
-// MemProf record memory profile in pprof
-func MemProf(w io.Writer) {
- admin.MemProf(w)
-}
-
-// GetCPUProfile start cpu profile monitor
-func GetCPUProfile(w io.Writer) {
- admin.GetCPUProfile(w)
-}
-
-// PrintGCSummary print gc information to io.Writer
-func PrintGCSummary(w io.Writer) {
- admin.PrintGCSummary(w)
-}
diff --git a/adapter/toolbox/profile_test.go b/adapter/toolbox/profile_test.go
deleted file mode 100644
index 07a20c4e..00000000
--- a/adapter/toolbox/profile_test.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox
-
-import (
- "os"
- "testing"
-)
-
-func TestProcessInput(t *testing.T) {
- ProcessInput("lookup goroutine", os.Stdout)
- ProcessInput("lookup heap", os.Stdout)
- ProcessInput("lookup threadcreate", os.Stdout)
- ProcessInput("lookup block", os.Stdout)
- ProcessInput("gc summary", os.Stdout)
-}
diff --git a/adapter/toolbox/statistics.go b/adapter/toolbox/statistics.go
deleted file mode 100644
index 47bfbbd5..00000000
--- a/adapter/toolbox/statistics.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox
-
-import (
- "time"
-
- "github.com/beego/beego/v2/server/web"
-)
-
-// Statistics struct
-type Statistics web.Statistics
-
-// URLMap contains several statistics struct to log different data
-type URLMap web.URLMap
-
-// AddStatistics add statistics task.
-// it needs request method, request url, request controller and statistics time duration
-func (m *URLMap) AddStatistics(requestMethod, requestURL, requestController string, requesttime time.Duration) {
- (*web.URLMap)(m).AddStatistics(requestMethod, requestURL, requestController, requesttime)
-}
-
-// GetMap put url statistics result in io.Writer
-func (m *URLMap) GetMap() map[string]interface{} {
- return (*web.URLMap)(m).GetMap()
-}
-
-// GetMapData return all mapdata
-func (m *URLMap) GetMapData() []map[string]interface{} {
- return (*web.URLMap)(m).GetMapData()
-}
-
-// StatisticsMap hosld global statistics data map
-var StatisticsMap *URLMap
-
-func init() {
- StatisticsMap = (*URLMap)(web.StatisticsMap)
-}
diff --git a/adapter/toolbox/statistics_test.go b/adapter/toolbox/statistics_test.go
deleted file mode 100644
index f4371c3f..00000000
--- a/adapter/toolbox/statistics_test.go
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox
-
-import (
- "encoding/json"
- "testing"
- "time"
-)
-
-func TestStatics(t *testing.T) {
- userApi := "/api/user"
- post := "POST"
- adminUser := "&admin.user"
- StatisticsMap.AddStatistics(post, userApi, adminUser, time.Duration(2000))
- StatisticsMap.AddStatistics(post, userApi, adminUser, time.Duration(120000))
- StatisticsMap.AddStatistics("GET", userApi, adminUser, time.Duration(13000))
- StatisticsMap.AddStatistics(post, "/api/admin", adminUser, time.Duration(14000))
- StatisticsMap.AddStatistics(post, "/api/user/astaxie", adminUser, time.Duration(12000))
- StatisticsMap.AddStatistics(post, "/api/user/xiemengjun", adminUser, time.Duration(13000))
- StatisticsMap.AddStatistics("DELETE", userApi, adminUser, time.Duration(1400))
- t.Log(StatisticsMap.GetMap())
-
- data := StatisticsMap.GetMapData()
- b, err := json.Marshal(data)
- if err != nil {
- t.Errorf(err.Error())
- }
-
- t.Log(string(b))
-}
diff --git a/adapter/toolbox/task.go b/adapter/toolbox/task.go
deleted file mode 100644
index 81864e9a..00000000
--- a/adapter/toolbox/task.go
+++ /dev/null
@@ -1,294 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 toolbox
-
-import (
- "context"
- "sort"
- "time"
-
- "github.com/beego/beego/v2/task"
-)
-
-// The bounds for each field.
-var (
- AdminTaskList map[string]Tasker
-)
-
-const (
- // Set the top bit if a star was included in the expression.
- starBit = 1 << 63
-)
-
-// Schedule time taks schedule
-type Schedule task.Schedule
-
-// TaskFunc task func type
-type TaskFunc func() error
-
-// Tasker task interface
-type Tasker interface {
- GetSpec() string
- GetStatus() string
- Run() error
- SetNext(time.Time)
- GetNext() time.Time
- SetPrev(time.Time)
- GetPrev() time.Time
-}
-
-// task error
-type taskerr struct {
- t time.Time
- errinfo string
-}
-
-// Task task struct
-// Deprecated
-type Task struct {
- // Deprecated
- Taskname string
- // Deprecated
- Spec *Schedule
- // Deprecated
- SpecStr string
- // Deprecated
- DoFunc TaskFunc
- // Deprecated
- Prev time.Time
- // Deprecated
- Next time.Time
- // Deprecated
- Errlist []*taskerr // like errtime:errinfo
- // Deprecated
- ErrLimit int // max length for the errlist, 0 stand for no limit
-
- delegate *task.Task
-}
-
-// NewTask add new task with name, time and func
-func NewTask(tname string, spec string, f TaskFunc) *Task {
- task := task.NewTask(tname, spec, func(ctx context.Context) error {
- return f()
- })
- return &Task{
- delegate: task,
- }
-}
-
-// GetSpec get spec string
-func (t *Task) GetSpec() string {
- t.initDelegate()
-
- return t.delegate.GetSpec(context.Background())
-}
-
-// GetStatus get current task status
-func (t *Task) GetStatus() string {
- t.initDelegate()
-
- return t.delegate.GetStatus(context.Background())
-}
-
-// Run run all tasks
-func (t *Task) Run() error {
- t.initDelegate()
- return t.delegate.Run(context.Background())
-}
-
-// SetNext set next time for this task
-func (t *Task) SetNext(now time.Time) {
- t.initDelegate()
- t.delegate.SetNext(context.Background(), now)
-}
-
-// GetNext get the next call time of this task
-func (t *Task) GetNext() time.Time {
- t.initDelegate()
- return t.delegate.GetNext(context.Background())
-}
-
-// SetPrev set prev time of this task
-func (t *Task) SetPrev(now time.Time) {
- t.initDelegate()
- t.delegate.SetPrev(context.Background(), now)
-}
-
-// GetPrev get prev time of this task
-func (t *Task) GetPrev() time.Time {
- t.initDelegate()
- return t.delegate.GetPrev(context.Background())
-}
-
-// six columns mean:
-// second:0-59
-// minute:0-59
-// hour:1-23
-// day:1-31
-// month:1-12
-// week:0-6(0 means Sunday)
-
-// SetCron some signals:
-// *: any time
-// ,: separate signal
-// -:duration
-// /n : do as n times of time duration
-// ///////////////////////////////////////////////////////
-// 0/30 * * * * * every 30s
-// 0 43 21 * * * 21:43
-// 0 15 05 * * * 05:15
-// 0 0 17 * * * 17:00
-// 0 0 17 * * 1 17:00 in every Monday
-// 0 0,10 17 * * 0,2,3 17:00 and 17:10 in every Sunday, Tuesday and Wednesday
-// 0 0-10 17 1 * * 17:00 to 17:10 in 1 min duration each time on the first day of month
-// 0 0 0 1,15 * 1 0:00 on the 1st day and 15th day of month
-// 0 42 4 1 * * 4:42 on the 1st day of month
-// 0 0 21 * * 1-6 21:00 from Monday to Saturday
-// 0 0,10,20,30,40,50 * * * * every 10 min duration
-// 0 */10 * * * * every 10 min duration
-// 0 * 1 * * * 1:00 to 1:59 in 1 min duration each time
-// 0 0 1 * * * 1:00
-// 0 0 */1 * * * 0 min of hour in 1 hour duration
-// 0 0 * * * * 0 min of hour in 1 hour duration
-// 0 2 8-20/3 * * * 8:02, 11:02, 14:02, 17:02, 20:02
-// 0 30 5 1,15 * * 5:30 on the 1st day and 15th day of month
-func (t *Task) SetCron(spec string) {
- t.initDelegate()
- t.delegate.SetCron(spec)
-}
-
-func (t *Task) initDelegate() {
- if t.delegate == nil {
- t.delegate = &task.Task{
- Taskname: t.Taskname,
- Spec: (*task.Schedule)(t.Spec),
- SpecStr: t.SpecStr,
- DoFunc: func(ctx context.Context) error {
- return t.DoFunc()
- },
- Prev: t.Prev,
- Next: t.Next,
- ErrLimit: t.ErrLimit,
- }
- }
-}
-
-// Next set schedule to next time
-func (s *Schedule) Next(t time.Time) time.Time {
- return (*task.Schedule)(s).Next(t)
-}
-
-// StartTask start all tasks
-func StartTask() {
- task.StartTask()
-}
-
-// StopTask stop all tasks
-func StopTask() {
- task.StopTask()
-}
-
-// AddTask add task with name
-func AddTask(taskname string, t Tasker) {
- task.AddTask(taskname, &oldToNewAdapter{delegate: t})
-}
-
-// DeleteTask delete task with name
-func DeleteTask(taskname string) {
- task.DeleteTask(taskname)
-}
-
-// ClearTask clear all tasks
-func ClearTask() {
- task.ClearTask()
-}
-
-// MapSorter sort map for tasker
-type MapSorter task.MapSorter
-
-// NewMapSorter create new tasker map
-func NewMapSorter(m map[string]Tasker) *MapSorter {
- newTaskerMap := make(map[string]task.Tasker, len(m))
-
- for key, value := range m {
- newTaskerMap[key] = &oldToNewAdapter{
- delegate: value,
- }
- }
-
- return (*MapSorter)(task.NewMapSorter(newTaskerMap))
-}
-
-// Sort sort tasker map
-func (ms *MapSorter) Sort() {
- sort.Sort(ms)
-}
-
-func (ms *MapSorter) Len() int { return len(ms.Keys) }
-
-func (ms *MapSorter) Less(i, j int) bool {
- if ms.Vals[i].GetNext(context.Background()).IsZero() {
- return false
- }
- if ms.Vals[j].GetNext(context.Background()).IsZero() {
- return true
- }
- return ms.Vals[i].GetNext(context.Background()).Before(ms.Vals[j].GetNext(context.Background()))
-}
-
-func (ms *MapSorter) Swap(i, j int) {
- ms.Vals[i], ms.Vals[j] = ms.Vals[j], ms.Vals[i]
- ms.Keys[i], ms.Keys[j] = ms.Keys[j], ms.Keys[i]
-}
-
-func init() {
- AdminTaskList = make(map[string]Tasker)
-}
-
-type oldToNewAdapter struct {
- delegate Tasker
-}
-
-func (o *oldToNewAdapter) GetSpec(ctx context.Context) string {
- return o.delegate.GetSpec()
-}
-
-func (o *oldToNewAdapter) GetStatus(ctx context.Context) string {
- return o.delegate.GetStatus()
-}
-
-func (o *oldToNewAdapter) Run(ctx context.Context) error {
- return o.delegate.Run()
-}
-
-func (o *oldToNewAdapter) SetNext(ctx context.Context, t time.Time) {
- o.delegate.SetNext(t)
-}
-
-func (o *oldToNewAdapter) GetNext(ctx context.Context) time.Time {
- return o.delegate.GetNext()
-}
-
-func (o *oldToNewAdapter) SetPrev(ctx context.Context, t time.Time) {
- o.delegate.SetPrev(t)
-}
-
-func (o *oldToNewAdapter) GetPrev(ctx context.Context) time.Time {
- return o.delegate.GetPrev()
-}
-
-func (o *oldToNewAdapter) GetTimeout(ctx context.Context) time.Duration {
- return 0
-}
diff --git a/adapter/tree.go b/adapter/tree.go
deleted file mode 100644
index 3d22d9ac..00000000
--- a/adapter/tree.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 adapter
-
-import (
- "github.com/beego/beego/v2/adapter/context"
- "github.com/beego/beego/v2/server/web"
- beecontext "github.com/beego/beego/v2/server/web/context"
-)
-
-// Tree has three elements: FixRouter/wildcard/leaves
-// fixRouter stores Fixed Router
-// wildcard stores params
-// leaves store the endpoint information
-type Tree web.Tree
-
-// NewTree return a new Tree
-func NewTree() *Tree {
- return (*Tree)(web.NewTree())
-}
-
-// AddTree will add tree to the exist Tree
-// prefix should has no params
-func (t *Tree) AddTree(prefix string, tree *Tree) {
- (*web.Tree)(t).AddTree(prefix, (*web.Tree)(tree))
-}
-
-// AddRouter call addseg function
-func (t *Tree) AddRouter(pattern string, runObject interface{}) {
- (*web.Tree)(t).AddRouter(pattern, runObject)
-}
-
-// Match router to runObject & params
-func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{}) {
- return (*web.Tree)(t).Match(pattern, (*beecontext.Context)(ctx))
-}
diff --git a/adapter/utils/caller.go b/adapter/utils/caller.go
deleted file mode 100644
index 7aec5000..00000000
--- a/adapter/utils/caller.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "github.com/beego/beego/v2/core/utils"
-)
-
-// GetFuncName get function name
-func GetFuncName(i interface{}) string {
- return utils.GetFuncName(i)
-}
diff --git a/adapter/utils/caller_test.go b/adapter/utils/caller_test.go
deleted file mode 100644
index 0675f0aa..00000000
--- a/adapter/utils/caller_test.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "strings"
- "testing"
-)
-
-func TestGetFuncName(t *testing.T) {
- name := GetFuncName(TestGetFuncName)
- t.Log(name)
- if !strings.HasSuffix(name, ".TestGetFuncName") {
- t.Error("get func name error")
- }
-}
diff --git a/adapter/utils/captcha/LICENSE b/adapter/utils/captcha/LICENSE
deleted file mode 100644
index 0ad73ae0..00000000
--- a/adapter/utils/captcha/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2011-2014 Dmitry Chestnykh
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/adapter/utils/captcha/README.md b/adapter/utils/captcha/README.md
deleted file mode 100644
index 07a4dc4d..00000000
--- a/adapter/utils/captcha/README.md
+++ /dev/null
@@ -1,45 +0,0 @@
-# Captcha
-
-an example for use captcha
-
-```
-package controllers
-
-import (
- "github.com/beego/beego/v2"
- "github.com/beego/beego/v2/client/cache"
- "github.com/beego/beego/v2/server/web/captcha"
-)
-
-var cpt *captcha.Captcha
-
-func init() {
- // use beego cache system store the captcha data
- store := cache.NewMemoryCache()
- cpt = captcha.NewWithFilter("/captcha/", store)
-}
-
-type MainController struct {
- beego.Controller
-}
-
-func (this *MainController) Get() {
- this.TplName = "index.tpl"
-}
-
-func (this *MainController) Post() {
- this.TplName = "index.tpl"
-
- this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
-}
-```
-
-template usage
-
-```
-{{.Success}}
-
-```
diff --git a/adapter/utils/captcha/captcha.go b/adapter/utils/captcha/captcha.go
deleted file mode 100644
index 7cdcab2d..00000000
--- a/adapter/utils/captcha/captcha.go
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 captcha implements generation and verification of image CAPTCHAs.
-// an example for use captcha
-//
-// ```
-// package controllers
-//
-// import (
-// "github.com/beego/beego/v2"
-// "github.com/beego/beego/v2/client/cache"
-// "github.com/beego/beego/v2/server/web/captcha"
-// )
-//
-// var cpt *captcha.Captcha
-//
-// func init() {
-// // use beego cache system store the captcha data
-// store := cache.NewMemoryCache()
-// cpt = captcha.NewWithFilter("/captcha/", store)
-// }
-//
-// type MainController struct {
-// beego.Controller
-// }
-//
-// func (this *MainController) Get() {
-// this.TplName = "index.tpl"
-// }
-//
-// func (this *MainController) Post() {
-// this.TplName = "index.tpl"
-//
-// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
-// }
-// ```
-//
-// template usage
-//
-// ```
-// {{.Success}}
-//
-// ```
-package captcha
-
-import (
- "html/template"
- "net/http"
- "time"
-
- "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 defaultChars = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
-
-const (
- // default captcha attributes
- challengeNums = 6
- expiration = 600 * time.Second
- fieldIDName = "captcha_id"
- fieldCaptchaName = "captcha"
- cachePrefix = "captcha_"
- defaultURLPrefix = "/captcha/"
-)
-
-// Captcha struct
-type Captcha captcha.Captcha
-
-// Handler beego filter handler for serve captcha image
-func (c *Captcha) Handler(ctx *context.Context) {
- (*captcha.Captcha)(c).Handler((*beecontext.Context)(ctx))
-}
-
-// CreateCaptchaHTML template func for output html
-func (c *Captcha) CreateCaptchaHTML() template.HTML {
- return (*captcha.Captcha)(c).CreateCaptchaHTML()
-}
-
-// CreateCaptcha create a new captcha id
-func (c *Captcha) CreateCaptcha() (string, error) {
- return (*captcha.Captcha)(c).CreateCaptcha()
-}
-
-// VerifyReq verify from a request
-func (c *Captcha) VerifyReq(req *http.Request) bool {
- return (*captcha.Captcha)(c).VerifyReq(req)
-}
-
-// Verify direct verify id and challenge string
-func (c *Captcha) Verify(id string, challenge string) (success bool) {
- return (*captcha.Captcha)(c).Verify(id, challenge)
-}
-
-// NewCaptcha create a new captcha.Captcha
-func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
- return (*Captcha)(captcha.NewCaptcha(urlPrefix, cache.CreateOldToNewAdapter(store)))
-}
-
-// NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image
-// and add a template func for output html
-func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
- return (*Captcha)(captcha.NewWithFilter(urlPrefix, cache.CreateOldToNewAdapter(store)))
-}
diff --git a/adapter/utils/captcha/image.go b/adapter/utils/captcha/image.go
deleted file mode 100644
index c28beb3c..00000000
--- a/adapter/utils/captcha/image.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 captcha
-
-import (
- "io"
-
- "github.com/beego/beego/v2/server/web/captcha"
-)
-
-// Image struct
-type Image captcha.Image
-
-// NewImage returns a new captcha image of the given width and height with the
-// given digits, where each digit must be in range 0-9.
-func NewImage(digits []byte, width, height int) *Image {
- return (*Image)(captcha.NewImage(digits, width, height))
-}
-
-// WriteTo writes captcha image in PNG format into the given writer.
-func (m *Image) WriteTo(w io.Writer) (int64, error) {
- return (*captcha.Image)(m).WriteTo(w)
-}
diff --git a/adapter/utils/captcha/image_test.go b/adapter/utils/captcha/image_test.go
deleted file mode 100644
index 8e3b1306..00000000
--- a/adapter/utils/captcha/image_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 captcha
-
-import (
- "testing"
-
- "github.com/beego/beego/v2/adapter/utils"
-)
-
-const (
- // Standard width and height of a captcha image.
- stdWidth = 240
- stdHeight = 80
-)
-
-type byteCounter struct {
- n int64
-}
-
-func (bc *byteCounter) Write(b []byte) (int, error) {
- bc.n += int64(len(b))
- return len(b), nil
-}
-
-func BenchmarkNewImage(b *testing.B) {
- b.StopTimer()
- d := utils.RandomCreateBytes(challengeNums, defaultChars...)
- b.StartTimer()
- for i := 0; i < b.N; i++ {
- NewImage(d, stdWidth, stdHeight)
- }
-}
-
-func BenchmarkImageWriteTo(b *testing.B) {
- b.StopTimer()
- d := utils.RandomCreateBytes(challengeNums, defaultChars...)
- b.StartTimer()
- counter := &byteCounter{}
- for i := 0; i < b.N; i++ {
- img := NewImage(d, stdWidth, stdHeight)
- img.WriteTo(counter)
- b.SetBytes(counter.n)
- counter.n = 0
- }
-}
diff --git a/adapter/utils/debug.go b/adapter/utils/debug.go
deleted file mode 100644
index 3e4e3a27..00000000
--- a/adapter/utils/debug.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "github.com/beego/beego/v2/core/utils"
-)
-
-// Display print the data in console
-func Display(data ...interface{}) {
- utils.Display(data...)
-}
-
-// GetDisplayString return data print string
-func GetDisplayString(data ...interface{}) string {
- return utils.GetDisplayString(data...)
-}
-
-// Stack get stack bytes
-func Stack(skip int, indent string) []byte {
- return utils.Stack(skip, indent)
-}
diff --git a/adapter/utils/debug_test.go b/adapter/utils/debug_test.go
deleted file mode 100644
index a748d20a..00000000
--- a/adapter/utils/debug_test.go
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "testing"
-)
-
-type mytype struct {
- next *mytype
- prev *mytype
-}
-
-func TestPrint(t *testing.T) {
- Display("v1", 1, "v2", 2, "v3", 3)
-}
-
-func TestPrintPoint(t *testing.T) {
- v1 := new(mytype)
- v2 := new(mytype)
-
- v1.prev = nil
- v1.next = v2
-
- v2.prev = v1
- v2.next = nil
-
- Display("v1", v1, "v2", v2)
-}
-
-func TestPrintString(t *testing.T) {
- str := GetDisplayString("v1", 1, "v2", 2)
- println(str)
-}
diff --git a/adapter/utils/file.go b/adapter/utils/file.go
deleted file mode 100644
index e6a785a2..00000000
--- a/adapter/utils/file.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "github.com/beego/beego/v2/core/utils"
-)
-
-// SelfPath gets compiled executable file absolute path
-func SelfPath() string {
- return utils.SelfPath()
-}
-
-// SelfDir gets compiled executable file directory
-func SelfDir() string {
- return utils.SelfDir()
-}
-
-// FileExists reports whether the named file or directory exists.
-func FileExists(name string) bool {
- return utils.FileExists(name)
-}
-
-// SearchFile Search a file in paths.
-// this is often used in search config file in /etc ~/
-func SearchFile(filename string, paths ...string) (fullpath string, err error) {
- return utils.SearchFile(filename, paths...)
-}
-
-// GrepFile like command grep -E
-// for example: GrepFile(`^hello`, "hello.txt")
-// \n is striped while read
-func GrepFile(patten string, filename string) (lines []string, err error) {
- return utils.GrepFile(patten, filename)
-}
diff --git a/adapter/utils/mail.go b/adapter/utils/mail.go
deleted file mode 100644
index 4ef89660..00000000
--- a/adapter/utils/mail.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import (
- "io"
-
- "github.com/beego/beego/v2/core/utils"
-)
-
-// Email is the type used for email messages
-type Email utils.Email
-
-// Attachment is a struct representing an email attachment.
-// Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question
-type Attachment utils.Attachment
-
-// NewEMail create new Email struct with config json.
-// config json is followed from Email struct fields.
-func NewEMail(config string) *Email {
- return (*Email)(utils.NewEMail(config))
-}
-
-// Bytes Make all send information to byte
-func (e *Email) Bytes() ([]byte, error) {
- return (*utils.Email)(e).Bytes()
-}
-
-// AttachFile Add attach file to the send mail
-func (e *Email) AttachFile(args ...string) (*Attachment, error) {
- a, err := (*utils.Email)(e).AttachFile(args...)
- if err != nil {
- return nil, err
- }
- return (*Attachment)(a), err
-}
-
-// Attach is used to attach content from an io.Reader to the email.
-// Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type.
-func (e *Email) Attach(r io.Reader, filename string, args ...string) (*Attachment, error) {
- a, err := (*utils.Email)(e).Attach(r, filename, args...)
- if err != nil {
- return nil, err
- }
- return (*Attachment)(a), err
-}
-
-// Send will send out the mail
-func (e *Email) Send() error {
- return (*utils.Email)(e).Send()
-}
diff --git a/adapter/utils/mail_test.go b/adapter/utils/mail_test.go
deleted file mode 100644
index c38356a2..00000000
--- a/adapter/utils/mail_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 utils
-
-import "testing"
-
-func TestMail(t *testing.T) {
- config := `{"username":"astaxie@gmail.com","password":"astaxie","host":"smtp.gmail.com","port":587}`
- mail := NewEMail(config)
- if mail.Username != "astaxie@gmail.com" {
- t.Fatal("email parse get username error")
- }
- if mail.Password != "astaxie" {
- t.Fatal("email parse get password error")
- }
- if mail.Host != "smtp.gmail.com" {
- t.Fatal("email parse get host error")
- }
- if mail.Port != 587 {
- t.Fatal("email parse get port error")
- }
- mail.To = []string{"xiemengjun@gmail.com"}
- mail.From = "astaxie@gmail.com"
- mail.Subject = "hi, just from beego!"
- mail.Text = "Text Body is, of course, supported!"
- mail.HTML = "
Fancy Html is supported, too!
"
- mail.AttachFile("/Users/astaxie/github/beego/beego.go")
- mail.Send()
-}
diff --git a/adapter/utils/pagination/controller.go b/adapter/utils/pagination/controller.go
deleted file mode 100644
index ab3fb83d..00000000
--- a/adapter/utils/pagination/controller.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 pagination
-
-import (
- "github.com/beego/beego/v2/adapter/context"
- beecontext "github.com/beego/beego/v2/server/web/context"
- "github.com/beego/beego/v2/server/web/pagination"
-)
-
-// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data("paginator").
-func SetPaginator(ctx *context.Context, per int, nums int64) (paginator *Paginator) {
- return (*Paginator)(pagination.SetPaginator((*beecontext.Context)(ctx), per, nums))
-}
diff --git a/adapter/utils/pagination/doc.go b/adapter/utils/pagination/doc.go
deleted file mode 100644
index 67530041..00000000
--- a/adapter/utils/pagination/doc.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-Package pagination provides utilities to setup a paginator within the
-context of a http request.
-
-Usage
-
-In your beego.Controller:
-
- package controllers
-
- import "github.com/beego/beego/v2/server/web/pagination"
-
- type PostsController struct {
- beego.Controller
- }
-
- func (this *PostsController) ListAllPosts() {
- // sets this.Data["paginator"] with the current offset (from the url query param)
- postsPerPage := 20
- paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
-
- // fetch the next 20 posts
- this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
- }
-
-
-In your view templates:
-
- {{if .paginator.HasPages}}
-
- {{end}}
-
-*/
-package pagination
diff --git a/adapter/utils/pagination/paginator.go b/adapter/utils/pagination/paginator.go
deleted file mode 100644
index cbf71da4..00000000
--- a/adapter/utils/pagination/paginator.go
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2014 beego Author. All Rights Reserved.
-//
-// 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 pagination
-
-import (
- "net/http"
-
- "github.com/beego/beego/v2/core/utils/pagination"
-)
-
-// Paginator within the state of a http request.
-type Paginator pagination.Paginator
-
-// PageNums Returns the total number of pages.
-func (p *Paginator) PageNums() int {
- return (*pagination.Paginator)(p).PageNums()
-}
-
-// Nums Returns the total number of items (e.g. from doing SQL count).
-func (p *Paginator) Nums() int64 {
- return (*pagination.Paginator)(p).Nums()
-}
-
-// SetNums Sets the total number of items.
-func (p *Paginator) SetNums(nums interface{}) {
- (*pagination.Paginator)(p).SetNums(nums)
-}
-
-// Page Returns the current page.
-func (p *Paginator) Page() int {
- return (*pagination.Paginator)(p).Page()
-}
-
-// Pages Returns a list of all pages.
-//
-// Usage (in a view template):
-//
-// {{range $index, $page := .paginator.Pages}}
-//