2020-07-22 14:50:08 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-12-12 13:28:58 +00:00
|
|
|
package adapter
|
2020-07-22 14:50:08 +00:00
|
|
|
|
|
|
|
import (
|
2020-12-12 13:28:58 +00:00
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"github.com/astaxie/beego/server/web"
|
2020-07-22 14:50:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-12-12 13:28:58 +00:00
|
|
|
|
2020-11-26 09:48:29 +00:00
|
|
|
// VERSION represent beego web framework version.
|
2020-12-12 13:28:58 +00:00
|
|
|
VERSION = beego.VERSION
|
2020-11-26 09:48:29 +00:00
|
|
|
|
2020-07-22 14:50:08 +00:00
|
|
|
// DEV is for develop
|
2020-12-12 13:28:58 +00:00
|
|
|
DEV = web.DEV
|
2020-07-22 14:50:08 +00:00
|
|
|
// PROD is for production
|
2020-12-12 13:28:58 +00:00
|
|
|
PROD = web.PROD
|
2020-07-22 14:50:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// M is Map shortcut
|
2020-12-12 13:28:58 +00:00
|
|
|
type M web.M
|
2020-07-22 14:50:08 +00:00
|
|
|
|
|
|
|
// Hook function to run
|
|
|
|
type hookfunc func() error
|
|
|
|
|
|
|
|
var (
|
2020-12-12 13:28:58 +00:00
|
|
|
hooks = make([]hookfunc, 0) // hook function slice to store the hookfunc
|
2020-07-22 14:50:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
2020-12-12 13:28:58 +00:00
|
|
|
for _, f := range hf {
|
|
|
|
web.AddAPPStartHook(func() error {
|
|
|
|
return f()
|
|
|
|
})
|
|
|
|
}
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2020-12-12 13:28:58 +00:00
|
|
|
web.Run(params...)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunWithMiddleWares Run beego application with middlewares.
|
|
|
|
func RunWithMiddleWares(addr string, mws ...MiddleWare) {
|
2020-12-12 13:28:58 +00:00
|
|
|
newMws := oldMiddlewareToNew(mws)
|
|
|
|
web.RunWithMiddleWares(addr, newMws...)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestBeegoInit is for test package init
|
|
|
|
func TestBeegoInit(ap string) {
|
2020-12-12 13:28:58 +00:00
|
|
|
web.TestBeegoInit(ap)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InitBeegoBeforeTest is for test package init
|
|
|
|
func InitBeegoBeforeTest(appConfigPath string) {
|
2020-12-12 13:28:58 +00:00
|
|
|
web.InitBeegoBeforeTest(appConfigPath)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|