diff --git a/pkg/adapter/admin.go b/pkg/adapter/admin.go
new file mode 100644
index 00000000..87e7259b
--- /dev/null
+++ b/pkg/adapter/admin.go
@@ -0,0 +1,48 @@
+// 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 (
+ "time"
+
+ "github.com/astaxie/beego/pkg/server/web"
+)
+
+// FilterMonitorFunc is default monitor filter when admin module is enable.
+// if this func returns, admin module records qps for this request by condition of this function logic.
+// usage:
+// func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool {
+// if method == "POST" {
+// return false
+// }
+// if t.Nanoseconds() < 100 {
+// return false
+// }
+// if strings.HasPrefix(requestPath, "/astaxie") {
+// return false
+// }
+// return true
+// }
+// beego.FilterMonitorFunc = MyFilterMonitor.
+var FilterMonitorFunc func(string, string, time.Duration, string, int) bool
+
+func init() {
+ FilterMonitorFunc = web.FilterMonitorFunc
+}
+
+// PrintTree prints all registered routers.
+func PrintTree() M {
+ return (M)(web.PrintTree())
+}
diff --git a/pkg/adapter/app.go b/pkg/adapter/app.go
new file mode 100644
index 00000000..64280a7b
--- /dev/null
+++ b/pkg/adapter/app.go
@@ -0,0 +1,261 @@
+// 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"
+
+ context2 "github.com/astaxie/beego/pkg/adapter/context"
+ "github.com/astaxie/beego/pkg/server/web"
+ "github.com/astaxie/beego/pkg/server/web/context"
+)
+
+var (
+ // BeeApp is an application instance
+ BeeApp *App
+)
+
+func init() {
+ // create beego application
+ BeeApp = (*App)(web.BeeApp)
+}
+
+// App defines beego application with a new PatternServeMux.
+type App web.App
+
+// NewApp returns a new beego application.
+func NewApp() *App {
+ return (*App)(web.NewApp())
+}
+
+// MiddleWare function for http.Handler
+type MiddleWare web.MiddleWare
+
+// Run beego application.
+func (app *App) Run(mws ...MiddleWare) {
+ newMws := oldMiddlewareToNew(mws)
+ (*web.App)(app).Run(newMws...)
+}
+
+func oldMiddlewareToNew(mws []MiddleWare) []web.MiddleWare {
+ newMws := make([]web.MiddleWare, 0, len(mws))
+ for _, old := range mws {
+ newMws = append(newMws, (web.MiddleWare)(old))
+ }
+ return newMws
+}
+
+// Router adds a patterned controller handler to BeeApp.
+// it's an alias method of App.Router.
+// usage:
+// simple router
+// beego.Router("/admin", &admin.UserController{})
+// beego.Router("/admin/index", &admin.ArticleController{})
+//
+// regex router
+//
+// beego.Router("/api/:id([0-9]+)", &controllers.RController{})
+//
+// custom rules
+// beego.Router("/api/list",&RestController{},"*:ListFood")
+// beego.Router("/api/create",&RestController{},"post:CreateFood")
+// beego.Router("/api/update",&RestController{},"put:UpdateFood")
+// beego.Router("/api/delete",&RestController{},"delete:DeleteFood")
+func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
+ return (*App)(web.Router(rootpath, c, mappingMethods...))
+}
+
+// UnregisterFixedRoute unregisters the route with the specified fixedRoute. It is particularly useful
+// in web applications that inherit most routes from a base webapp via the underscore
+// import, and aim to overwrite only certain paths.
+// The method parameter can be empty or "*" for all HTTP methods, or a particular
+// method type (e.g. "GET" or "POST") for selective removal.
+//
+// Usage (replace "GET" with "*" for all methods):
+// beego.UnregisterFixedRoute("/yourpreviouspath", "GET")
+// beego.Router("/yourpreviouspath", yourControllerAddress, "get:GetNewPage")
+func UnregisterFixedRoute(fixedRoute string, method string) *App {
+ return (*App)(web.UnregisterFixedRoute(fixedRoute, method))
+}
+
+// Include will generate router file in the router/xxx.go from the controller's comments
+// usage:
+// beego.Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
+// type BankAccount struct{
+// beego.Controller
+// }
+//
+// register the function
+// func (b *BankAccount)Mapping(){
+// b.Mapping("ShowAccount" , b.ShowAccount)
+// b.Mapping("ModifyAccount", b.ModifyAccount)
+// }
+//
+// //@router /account/:id [get]
+// func (b *BankAccount) ShowAccount(){
+// //logic
+// }
+//
+//
+// //@router /account/:id [post]
+// func (b *BankAccount) ModifyAccount(){
+// //logic
+// }
+//
+// the comments @router url methodlist
+// url support all the function Router's pattern
+// methodlist [get post head put delete options *]
+func Include(cList ...ControllerInterface) *App {
+ newList := oldToNewCtrlIntfs(cList)
+ return (*App)(web.Include(newList...))
+}
+
+func oldToNewCtrlIntfs(cList []ControllerInterface) []web.ControllerInterface {
+ newList := make([]web.ControllerInterface, 0, len(cList))
+ for _, c := range cList {
+ newList = append(newList, c)
+ }
+ return newList
+}
+
+// RESTRouter adds a restful controller handler to BeeApp.
+// its' controller implements beego.ControllerInterface and
+// defines a param "pattern/:objectId" to visit each resource.
+func RESTRouter(rootpath string, c ControllerInterface) *App {
+ return (*App)(web.RESTRouter(rootpath, c))
+}
+
+// AutoRouter adds defined controller handler to BeeApp.
+// it's same to App.AutoRouter.
+// if beego.AddAuto(&MainContorlller{}) and MainController has methods List and Page,
+// visit the url /main/list to exec List function or /main/page to exec Page function.
+func AutoRouter(c ControllerInterface) *App {
+ return (*App)(web.AutoRouter(c))
+}
+
+// AutoPrefix adds controller handler to BeeApp with prefix.
+// it's same to App.AutoRouterWithPrefix.
+// if beego.AutoPrefix("/admin",&MainContorlller{}) and MainController has methods List and Page,
+// visit the url /admin/main/list to exec List function or /admin/main/page to exec Page function.
+func AutoPrefix(prefix string, c ControllerInterface) *App {
+ return (*App)(web.AutoPrefix(prefix, c))
+}
+
+// Get used to register router for Get method
+// usage:
+// beego.Get("/", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Get(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Get(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Post used to register router for Post method
+// usage:
+// beego.Post("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Post(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Post(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Delete used to register router for Delete method
+// usage:
+// beego.Delete("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Delete(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Delete(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Put used to register router for Put method
+// usage:
+// beego.Put("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Put(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Put(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Head used to register router for Head method
+// usage:
+// beego.Head("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Head(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Head(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Options used to register router for Options method
+// usage:
+// beego.Options("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Options(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Options(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Patch used to register router for Patch method
+// usage:
+// beego.Patch("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Patch(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Patch(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Any used to register router for all methods
+// usage:
+// beego.Any("/api", func(ctx *context.Context){
+// ctx.Output.Body("hello world")
+// })
+func Any(rootpath string, f FilterFunc) *App {
+ return (*App)(web.Any(rootpath, func(ctx *context.Context) {
+ f((*context2.Context)(ctx))
+ }))
+}
+
+// Handler used to register a Handler router
+// usage:
+// beego.Handler("/api", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
+// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
+// }))
+func Handler(rootpath string, h http.Handler, options ...interface{}) *App {
+ return (*App)(web.Handler(rootpath, h, options))
+}
+
+// InsertFilter adds a FilterFunc with pattern condition and action constant.
+// The pos means action constant including
+// beego.BeforeStatic, beego.BeforeRouter, beego.BeforeExec, beego.AfterExec and beego.FinishRouter.
+// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
+func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App {
+ return (*App)(web.InsertFilter(pattern, pos, func(ctx *context.Context) {
+ filter((*context2.Context)(ctx))
+ }, params...))
+}
diff --git a/pkg/adapter/beego.go b/pkg/adapter/beego.go
new file mode 100644
index 00000000..efd2d4ea
--- /dev/null
+++ b/pkg/adapter/beego.go
@@ -0,0 +1,75 @@
+// 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/astaxie/beego/pkg/server/web"
+)
+
+const (
+ // VERSION represent beego web framework version.
+ VERSION = web.VERSION
+
+ // DEV is for develop
+ DEV = web.DEV
+ // PROD is for production
+ PROD = web.PROD
+)
+
+// M is Map shortcut
+type M web.M
+
+// Hook function to run
+type hookfunc func() error
+
+var (
+ hooks = make([]hookfunc, 0) // hook function slice to store the hookfunc
+)
+
+// AddAPPStartHook is used to register the hookfunc
+// The hookfuncs will run in beego.Run()
+// such as initiating session , starting middleware , building template, starting admin control and so on.
+func AddAPPStartHook(hf ...hookfunc) {
+ for _, f := range hf {
+ web.AddAPPStartHook(func() error {
+ return f()
+ })
+ }
+}
+
+// Run beego application.
+// beego.Run() default run on HttpPort
+// beego.Run("localhost")
+// beego.Run(":8089")
+// beego.Run("127.0.0.1:8089")
+func Run(params ...string) {
+ web.Run(params...)
+}
+
+// RunWithMiddleWares Run beego application with middlewares.
+func RunWithMiddleWares(addr string, mws ...MiddleWare) {
+ newMws := oldMiddlewareToNew(mws)
+ web.RunWithMiddleWares(addr, newMws...)
+}
+
+// TestBeegoInit is for test package init
+func TestBeegoInit(ap string) {
+ web.TestBeegoInit(ap)
+}
+
+// InitBeegoBeforeTest is for test package init
+func InitBeegoBeforeTest(appConfigPath string) {
+ web.InitBeegoBeforeTest(appConfigPath)
+}
diff --git a/pkg/adapter/build_info.go b/pkg/adapter/build_info.go
new file mode 100644
index 00000000..1e8dacf0
--- /dev/null
+++ b/pkg/adapter/build_info.go
@@ -0,0 +1,27 @@
+// 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 adapter
+
+var (
+ BuildVersion string
+ BuildGitRevision string
+ BuildStatus string
+ BuildTag string
+ BuildTime string
+
+ GoVersion string
+
+ GitBranch string
+)
diff --git a/pkg/adapter/config.go b/pkg/adapter/config.go
new file mode 100644
index 00000000..1491722c
--- /dev/null
+++ b/pkg/adapter/config.go
@@ -0,0 +1,179 @@
+// 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 (
+ context2 "context"
+
+ "github.com/astaxie/beego/pkg/adapter/session"
+ newCfg "github.com/astaxie/beego/pkg/infrastructure/config"
+ "github.com/astaxie/beego/pkg/server/web"
+)
+
+// Config is the main struct for BConfig
+type Config web.Config
+
+// Listen holds for http and https related config
+type Listen web.Listen
+
+// WebConfig holds web related config
+type WebConfig web.WebConfig
+
+// SessionConfig holds session related config
+type SessionConfig web.SessionConfig
+
+// LogConfig holds Log related config
+type LogConfig web.LogConfig
+
+var (
+ // BConfig is the default config for Application
+ BConfig *Config
+ // AppConfig is the instance of Config, store the config information from file
+ AppConfig *beegoAppConfig
+ // AppPath is the absolute path to the app
+ AppPath string
+ // GlobalSessions is the instance for the session manager
+ GlobalSessions *session.Manager
+
+ // appConfigPath is the path to the config files
+ appConfigPath string
+ // appConfigProvider is the provider for the config, default is ini
+ appConfigProvider = "ini"
+ // WorkPath is the absolute path to project root directory
+ WorkPath string
+)
+
+func init() {
+ BConfig = (*Config)(web.BConfig)
+ AppPath = web.AppPath
+
+ WorkPath = web.WorkPath
+
+ AppConfig = &beegoAppConfig{innerConfig: (newCfg.Configer)(web.AppConfig)}
+}
+
+// LoadAppConfig allow developer to apply a config file
+func LoadAppConfig(adapterName, configPath string) error {
+ return web.LoadAppConfig(adapterName, configPath)
+}
+
+type beegoAppConfig struct {
+ innerConfig newCfg.Configer
+}
+
+func (b *beegoAppConfig) Set(key, val string) error {
+ if err := b.innerConfig.Set(context2.Background(), BConfig.RunMode+"::"+key, val); err != nil {
+ return b.innerConfig.Set(context2.Background(), key, val)
+ }
+ return nil
+}
+
+func (b *beegoAppConfig) String(key string) string {
+ if v, err := b.innerConfig.String(context2.Background(), BConfig.RunMode+"::"+key); v != "" && err != nil {
+ return v
+ }
+ res, _ := b.innerConfig.String(context2.Background(), key)
+ return res
+}
+
+func (b *beegoAppConfig) Strings(key string) []string {
+ if v, err := b.innerConfig.Strings(context2.Background(), BConfig.RunMode+"::"+key); len(v) > 0 && err != nil {
+ return v
+ }
+ res, _ := b.innerConfig.Strings(context2.Background(), key)
+ return res
+}
+
+func (b *beegoAppConfig) Int(key string) (int, error) {
+ if v, err := b.innerConfig.Int(context2.Background(), BConfig.RunMode+"::"+key); err == nil {
+ return v, nil
+ }
+ return b.innerConfig.Int(context2.Background(), key)
+}
+
+func (b *beegoAppConfig) Int64(key string) (int64, error) {
+ if v, err := b.innerConfig.Int64(context2.Background(), BConfig.RunMode+"::"+key); err == nil {
+ return v, nil
+ }
+ return b.innerConfig.Int64(context2.Background(), key)
+}
+
+func (b *beegoAppConfig) Bool(key string) (bool, error) {
+ if v, err := b.innerConfig.Bool(context2.Background(), BConfig.RunMode+"::"+key); err == nil {
+ return v, nil
+ }
+ return b.innerConfig.Bool(context2.Background(), key)
+}
+
+func (b *beegoAppConfig) Float(key string) (float64, error) {
+ if v, err := b.innerConfig.Float(context2.Background(), BConfig.RunMode+"::"+key); err == nil {
+ return v, nil
+ }
+ return b.innerConfig.Float(context2.Background(), key)
+}
+
+func (b *beegoAppConfig) DefaultString(key string, defaultVal string) string {
+ if v := b.String(key); v != "" {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DefaultStrings(key string, defaultVal []string) []string {
+ if v := b.Strings(key); len(v) != 0 {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DefaultInt(key string, defaultVal int) int {
+ if v, err := b.Int(key); err == nil {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DefaultInt64(key string, defaultVal int64) int64 {
+ if v, err := b.Int64(key); err == nil {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DefaultBool(key string, defaultVal bool) bool {
+ if v, err := b.Bool(key); err == nil {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DefaultFloat(key string, defaultVal float64) float64 {
+ if v, err := b.Float(key); err == nil {
+ return v
+ }
+ return defaultVal
+}
+
+func (b *beegoAppConfig) DIY(key string) (interface{}, error) {
+ return b.innerConfig.DIY(context2.Background(), key)
+}
+
+func (b *beegoAppConfig) GetSection(section string) (map[string]string, error) {
+ return b.innerConfig.GetSection(context2.Background(), section)
+}
+
+func (b *beegoAppConfig) SaveConfigFile(filename string) error {
+ return b.innerConfig.SaveConfigFile(context2.Background(), filename)
+}
diff --git a/pkg/adapter/controller.go b/pkg/adapter/controller.go
new file mode 100644
index 00000000..010add64
--- /dev/null
+++ b/pkg/adapter/controller.go
@@ -0,0 +1,401 @@
+// 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 (
+ "mime/multipart"
+ "net/url"
+
+ "github.com/astaxie/beego/pkg/adapter/context"
+ "github.com/astaxie/beego/pkg/adapter/session"
+ webContext "github.com/astaxie/beego/pkg/server/web/context"
+
+ "github.com/astaxie/beego/pkg/server/web"
+)
+
+var (
+ // ErrAbort custom error when user stop request handler manually.
+ ErrAbort = web.ErrAbort
+ // GlobalControllerRouter store comments with controller. pkgpath+controller:comments
+ GlobalControllerRouter = web.GlobalControllerRouter
+)
+
+// ControllerFilter store the filter for controller
+type ControllerFilter web.ControllerFilter
+
+// ControllerFilterComments store the comment for controller level filter
+type ControllerFilterComments web.ControllerFilterComments
+
+// ControllerImportComments store the import comment for controller needed
+type ControllerImportComments web.ControllerImportComments
+
+// ControllerComments store the comment for the controller method
+type ControllerComments web.ControllerComments
+
+// ControllerCommentsSlice implements the sort interface
+type ControllerCommentsSlice web.ControllerCommentsSlice
+
+func (p ControllerCommentsSlice) Len() int {
+ return (web.ControllerCommentsSlice)(p).Len()
+}
+func (p ControllerCommentsSlice) Less(i, j int) bool {
+ return (web.ControllerCommentsSlice)(p).Less(i, j)
+}
+func (p ControllerCommentsSlice) Swap(i, j int) {
+ (web.ControllerCommentsSlice)(p).Swap(i, j)
+}
+
+// Controller defines some basic http request handler operations, such as
+// http context, template and view, session and xsrf.
+type Controller web.Controller
+
+// ControllerInterface is an interface to uniform all controller handler.
+type ControllerInterface web.ControllerInterface
+
+// Init generates default values of controller operations.
+func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
+ (*web.Controller)(c).Init((*webContext.Context)(ctx), controllerName, actionName, app)
+}
+
+// Prepare runs after Init before request function execution.
+func (c *Controller) Prepare() {
+ (*web.Controller)(c).Prepare()
+}
+
+// Finish runs after request function execution.
+func (c *Controller) Finish() {
+ (*web.Controller)(c).Finish()
+}
+
+// Get adds a request function to handle GET request.
+func (c *Controller) Get() {
+ (*web.Controller)(c).Get()
+}
+
+// Post adds a request function to handle POST request.
+func (c *Controller) Post() {
+ (*web.Controller)(c).Post()
+}
+
+// Delete adds a request function to handle DELETE request.
+func (c *Controller) Delete() {
+ (*web.Controller)(c).Delete()
+}
+
+// Put adds a request function to handle PUT request.
+func (c *Controller) Put() {
+ (*web.Controller)(c).Put()
+}
+
+// Head adds a request function to handle HEAD request.
+func (c *Controller) Head() {
+ (*web.Controller)(c).Head()
+}
+
+// Patch adds a request function to handle PATCH request.
+func (c *Controller) Patch() {
+ (*web.Controller)(c).Patch()
+}
+
+// Options adds a request function to handle OPTIONS request.
+func (c *Controller) Options() {
+ (*web.Controller)(c).Options()
+}
+
+// Trace adds a request function to handle Trace request.
+// this method SHOULD NOT be overridden.
+// https://tools.ietf.org/html/rfc7231#section-4.3.8
+// The TRACE method requests a remote, application-level loop-back of
+// the request message. The final recipient of the request SHOULD
+// reflect the message received, excluding some fields described below,
+// back to the client as the message body of a 200 (OK) response with a
+// Content-Type of "message/http" (Section 8.3.1 of [RFC7230]).
+func (c *Controller) Trace() {
+ (*web.Controller)(c).Trace()
+}
+
+// HandlerFunc call function with the name
+func (c *Controller) HandlerFunc(fnname string) bool {
+ return (*web.Controller)(c).HandlerFunc(fnname)
+}
+
+// URLMapping register the internal Controller router.
+func (c *Controller) URLMapping() {
+ (*web.Controller)(c).URLMapping()
+}
+
+// Mapping the method to function
+func (c *Controller) Mapping(method string, fn func()) {
+ (*web.Controller)(c).Mapping(method, fn)
+}
+
+// Render sends the response with rendered template bytes as text/html type.
+func (c *Controller) Render() error {
+ return (*web.Controller)(c).Render()
+}
+
+// RenderString returns the rendered template string. Do not send out response.
+func (c *Controller) RenderString() (string, error) {
+ return (*web.Controller)(c).RenderString()
+}
+
+// RenderBytes returns the bytes of rendered template string. Do not send out response.
+func (c *Controller) RenderBytes() ([]byte, error) {
+ return (*web.Controller)(c).RenderBytes()
+}
+
+// Redirect sends the redirection response to url with status code.
+func (c *Controller) Redirect(url string, code int) {
+ (*web.Controller)(c).Redirect(url, code)
+}
+
+// SetData set the data depending on the accepted
+func (c *Controller) SetData(data interface{}) {
+ (*web.Controller)(c).SetData(data)
+}
+
+// Abort stops controller handler and show the error data if code is defined in ErrorMap or code string.
+func (c *Controller) Abort(code string) {
+ (*web.Controller)(c).Abort(code)
+}
+
+// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
+func (c *Controller) CustomAbort(status int, body string) {
+ (*web.Controller)(c).CustomAbort(status, body)
+}
+
+// StopRun makes panic of USERSTOPRUN error and go to recover function if defined.
+func (c *Controller) StopRun() {
+ (*web.Controller)(c).StopRun()
+}
+
+// URLFor does another controller handler in this request function.
+// it goes to this controller method if endpoint is not clear.
+func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
+ return (*web.Controller)(c).URLFor(endpoint, values...)
+}
+
+// ServeJSON sends a json response with encoding charset.
+func (c *Controller) ServeJSON(encoding ...bool) {
+ (*web.Controller)(c).ServeJSON(encoding...)
+}
+
+// ServeJSONP sends a jsonp response.
+func (c *Controller) ServeJSONP() {
+ (*web.Controller)(c).ServeJSONP()
+}
+
+// ServeXML sends xml response.
+func (c *Controller) ServeXML() {
+ (*web.Controller)(c).ServeXML()
+}
+
+// ServeYAML sends yaml response.
+func (c *Controller) ServeYAML() {
+ (*web.Controller)(c).ServeYAML()
+}
+
+// ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
+func (c *Controller) ServeFormatted(encoding ...bool) {
+ (*web.Controller)(c).ServeFormatted(encoding...)
+}
+
+// Input returns the input data map from POST or PUT request body and query string.
+func (c *Controller) Input() url.Values {
+ return (*web.Controller)(c).Input()
+}
+
+// ParseForm maps input data map to obj struct.
+func (c *Controller) ParseForm(obj interface{}) error {
+ return (*web.Controller)(c).ParseForm(obj)
+}
+
+// GetString returns the input value by key string or the default value while it's present and input is blank
+func (c *Controller) GetString(key string, def ...string) string {
+ return (*web.Controller)(c).GetString(key, def...)
+}
+
+// GetStrings returns the input string slice by key string or the default value while it's present and input is blank
+// it's designed for multi-value input field such as checkbox(input[type=checkbox]), multi-selection.
+func (c *Controller) GetStrings(key string, def ...[]string) []string {
+ return (*web.Controller)(c).GetStrings(key, def...)
+}
+
+// GetInt returns input as an int or the default value while it's present and input is blank
+func (c *Controller) GetInt(key string, def ...int) (int, error) {
+ return (*web.Controller)(c).GetInt(key, def...)
+}
+
+// GetInt8 return input as an int8 or the default value while it's present and input is blank
+func (c *Controller) GetInt8(key string, def ...int8) (int8, error) {
+ return (*web.Controller)(c).GetInt8(key, def...)
+}
+
+// GetUint8 return input as an uint8 or the default value while it's present and input is blank
+func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error) {
+ return (*web.Controller)(c).GetUint8(key, def...)
+}
+
+// GetInt16 returns input as an int16 or the default value while it's present and input is blank
+func (c *Controller) GetInt16(key string, def ...int16) (int16, error) {
+ return (*web.Controller)(c).GetInt16(key, def...)
+}
+
+// GetUint16 returns input as an uint16 or the default value while it's present and input is blank
+func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error) {
+ return (*web.Controller)(c).GetUint16(key, def...)
+}
+
+// GetInt32 returns input as an int32 or the default value while it's present and input is blank
+func (c *Controller) GetInt32(key string, def ...int32) (int32, error) {
+ return (*web.Controller)(c).GetInt32(key, def...)
+}
+
+// GetUint32 returns input as an uint32 or the default value while it's present and input is blank
+func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error) {
+ return (*web.Controller)(c).GetUint32(key, def...)
+}
+
+// GetInt64 returns input value as int64 or the default value while it's present and input is blank.
+func (c *Controller) GetInt64(key string, def ...int64) (int64, error) {
+ return (*web.Controller)(c).GetInt64(key, def...)
+}
+
+// GetUint64 returns input value as uint64 or the default value while it's present and input is blank.
+func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error) {
+ return (*web.Controller)(c).GetUint64(key, def...)
+}
+
+// GetBool returns input value as bool or the default value while it's present and input is blank.
+func (c *Controller) GetBool(key string, def ...bool) (bool, error) {
+ return (*web.Controller)(c).GetBool(key, def...)
+}
+
+// GetFloat returns input value as float64 or the default value while it's present and input is blank.
+func (c *Controller) GetFloat(key string, def ...float64) (float64, error) {
+ return (*web.Controller)(c).GetFloat(key, def...)
+}
+
+// GetFile returns the file data in file upload field named as key.
+// it returns the first one of multi-uploaded files.
+func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error) {
+ return (*web.Controller)(c).GetFile(key)
+}
+
+// GetFiles return multi-upload files
+// files, err:=c.GetFiles("myfiles")
+// if err != nil {
+// http.Error(w, err.Error(), http.StatusNoContent)
+// return
+// }
+// for i, _ := range files {
+// //for each fileheader, get a handle to the actual file
+// file, err := files[i].Open()
+// defer file.Close()
+// if err != nil {
+// http.Error(w, err.Error(), http.StatusInternalServerError)
+// return
+// }
+// //create destination file making sure the path is writeable.
+// dst, err := os.Create("upload/" + files[i].Filename)
+// defer dst.Close()
+// if err != nil {
+// http.Error(w, err.Error(), http.StatusInternalServerError)
+// return
+// }
+// //copy the uploaded file to the destination file
+// if _, err := io.Copy(dst, file); err != nil {
+// http.Error(w, err.Error(), http.StatusInternalServerError)
+// return
+// }
+// }
+func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
+ return (*web.Controller)(c).GetFiles(key)
+}
+
+// SaveToFile saves uploaded file to new path.
+// it only operates the first one of mutil-upload form file field.
+func (c *Controller) SaveToFile(fromfile, tofile string) error {
+ return (*web.Controller)(c).SaveToFile(fromfile, tofile)
+}
+
+// StartSession starts session and load old session data info this controller.
+func (c *Controller) StartSession() session.Store {
+ s := (*web.Controller)(c).StartSession()
+ return session.CreateNewToOldStoreAdapter(s)
+}
+
+// SetSession puts value into session.
+func (c *Controller) SetSession(name interface{}, value interface{}) {
+ (*web.Controller)(c).SetSession(name, value)
+}
+
+// GetSession gets value from session.
+func (c *Controller) GetSession(name interface{}) interface{} {
+ return (*web.Controller)(c).GetSession(name)
+}
+
+// DelSession removes value from session.
+func (c *Controller) DelSession(name interface{}) {
+ (*web.Controller)(c).DelSession(name)
+}
+
+// SessionRegenerateID regenerates session id for this session.
+// the session data have no changes.
+func (c *Controller) SessionRegenerateID() {
+ (*web.Controller)(c).SessionRegenerateID()
+}
+
+// DestroySession cleans session data and session cookie.
+func (c *Controller) DestroySession() {
+ (*web.Controller)(c).DestroySession()
+}
+
+// IsAjax returns this request is ajax or not.
+func (c *Controller) IsAjax() bool {
+ return (*web.Controller)(c).IsAjax()
+}
+
+// GetSecureCookie returns decoded cookie value from encoded browser cookie values.
+func (c *Controller) GetSecureCookie(Secret, key string) (string, bool) {
+ return (*web.Controller)(c).GetSecureCookie(Secret, key)
+}
+
+// SetSecureCookie puts value into cookie after encoded the value.
+func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{}) {
+ (*web.Controller)(c).SetSecureCookie(Secret, name, value, others...)
+}
+
+// XSRFToken creates a CSRF token string and returns.
+func (c *Controller) XSRFToken() string {
+ return (*web.Controller)(c).XSRFToken()
+}
+
+// CheckXSRFCookie checks xsrf token in this request is valid or not.
+// the token can provided in request header "X-Xsrftoken" and "X-CsrfToken"
+// or in form field value named as "_xsrf".
+func (c *Controller) CheckXSRFCookie() bool {
+ return (*web.Controller)(c).CheckXSRFCookie()
+}
+
+// XSRFFormHTML writes an input field contains xsrf token value.
+func (c *Controller) XSRFFormHTML() string {
+ return (*web.Controller)(c).XSRFFormHTML()
+}
+
+// GetControllerAndAction gets the executing controller name and action name.
+func (c *Controller) GetControllerAndAction() (string, string) {
+ return (*web.Controller)(c).GetControllerAndAction()
+}
diff --git a/pkg/adapter/error.go b/pkg/adapter/error.go
new file mode 100644
index 00000000..4f08aa8c
--- /dev/null
+++ b/pkg/adapter/error.go
@@ -0,0 +1,202 @@
+// 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"
+
+ "github.com/astaxie/beego/pkg/adapter/context"
+ beecontext "github.com/astaxie/beego/pkg/server/web/context"
+
+ "github.com/astaxie/beego/pkg/server/web"
+)
+
+const (
+ errorTypeHandler = iota
+ errorTypeController
+)
+
+var tpl = `
+
+
+