代码拉取完成,页面将自动刷新
/*
Nging is a toolbox for webmasters
Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package driver
import (
"github.com/admpub/nging/application/library/common"
"github.com/admpub/nging/application/library/dbmanager/result"
"github.com/webx-top/echo"
)
var (
drivers = map[string]Driver{}
DefaultDriver = &BaseDriver{}
)
type Driver interface {
Init(echo.Context, *DbAuth)
SetURLGenerator(func(string, ...string) string) Driver
GenURL(string, ...string) string
Results() []result.Resulter
AddResults(...result.Resulter) Driver
SetResults(...result.Resulter) Driver
SaveResults() Driver
SavedResults() interface{}
IsSupported(string) bool
Login() error
Logout() error
ProcessList() error
Privileges() error
Info() error
CreateDb() error
ModifyDb() error
ListDb() error
CreateTable() error
ModifyTable() error
ListTable() error
ViewTable() error
ListData() error
CreateData() error
Indexes() error
Foreign() error
Trigger() error
RunCommand() error
Import() error
Export() error
Analysis() error
Name() string
}
func NewBaseDriver() *BaseDriver {
return &BaseDriver{}
}
type BaseDriver struct {
echo.Context
*DbAuth
results []result.Resulter
urlGenerator func(string, ...string) string
}
func (m *BaseDriver) SetURLGenerator(fn func(string, ...string) string) Driver {
m.urlGenerator = fn
return m
}
func (m *BaseDriver) GenURL(op string, args ...string) string {
return m.urlGenerator(op, args...)
}
func (m *BaseDriver) Results() []result.Resulter {
return m.results
}
func (m *BaseDriver) AddResults(rs ...result.Resulter) Driver {
if m.results == nil {
m.results = []result.Resulter{}
}
m.results = append(m.results, rs...)
return m
}
func (m *BaseDriver) SetResults(rs ...result.Resulter) Driver {
m.results = rs
return m
}
func (m *BaseDriver) SaveResults() Driver {
if m.results == nil {
return m
}
/*
if v, y := m.Flash(`dbMgrResults`).([]result.Resulter); y {
m.results = append(v, m.results...)
}
*/
m.Session().AddFlash(m.results, `dbMgrResults`)
return m
}
func (m *BaseDriver) SavedResults() interface{} {
if v := m.Flash(`dbMgrResults`); v != nil {
return v
}
return m.results
}
func (m *BaseDriver) Init(ctx echo.Context, auth *DbAuth) {
m.Context = ctx
m.DbAuth = auth
}
func (m *BaseDriver) IsSupported(operation string) bool {
return true
}
func (m *BaseDriver) Login() error {
return nil
}
func (m *BaseDriver) Logout() error {
return nil
}
func (m *BaseDriver) ProcessList() error {
return nil
}
func (m *BaseDriver) Privileges() error {
return nil
}
func (m *BaseDriver) Info() error {
return nil
}
func (m *BaseDriver) CreateDb() error {
return nil
}
func (m *BaseDriver) ModifyDb() error {
return nil
}
func (m *BaseDriver) ListDb() error {
return nil
}
func (m *BaseDriver) CreateTable() error {
return nil
}
func (m *BaseDriver) ModifyTable() error {
return nil
}
func (m *BaseDriver) ListTable() error {
return nil
}
func (m *BaseDriver) ViewTable() error {
return nil
}
func (m *BaseDriver) ListData() error {
return nil
}
func (m *BaseDriver) CreateData() error {
return nil
}
func (m *BaseDriver) Indexes() error {
return nil
}
func (m *BaseDriver) Foreign() error {
return nil
}
func (m *BaseDriver) Trigger() error {
return nil
}
func (m *BaseDriver) RunCommand() error {
return nil
}
func (m *BaseDriver) Import() error {
return nil
}
func (m *BaseDriver) Export() error {
return nil
}
func (m *BaseDriver) Analysis() error {
data := m.Data()
data.SetInfo(m.T(`不支持此功能`), 0)
return m.JSON(data)
}
func (m *BaseDriver) Name() string {
return `Base`
}
//========================================================
func (m *BaseDriver) CheckErr(err error) interface{} {
return common.Err(m.Context, err)
}
func (m *BaseDriver) SetOk(msg string) {
m.Session().AddFlash(common.Ok(msg))
}
func (m *BaseDriver) SetFail(msg string) {
m.Session().AddFlash(msg)
}
func (m *BaseDriver) ReturnTo(rets ...string) error {
returnTo := m.Form(`return_to`)
if len(returnTo) == 0 {
if len(rets) > 0 {
returnTo = rets[0]
} else {
returnTo = m.Request().Referer()
}
}
m.SaveResults()
return m.Redirect(returnTo)
}
func Register(name string, driver Driver) {
drivers[name] = driver
}
func Get(name string) (Driver, bool) {
d, y := drivers[name]
return d, y
}
func GetForce(name string) Driver {
d, y := drivers[name]
if !y {
d = DefaultDriver
}
return d
}
func Has(name string) bool {
_, y := drivers[name]
return y
}
func GetAll() map[string]Driver {
return drivers
}
func Unregister(name string) {
_, y := drivers[name]
if y {
delete(drivers, name)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。