mvc

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Copyright 2016 Wenhui Shen <www.webx.top>

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.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAppHasBeenDisabled     = errors.New(`This module has been disabled`)
	ErrAppHasNotBeenInstalled = errors.New(`This module has not been installed`)
	ErrAppHasExpired          = errors.New(`This module has expired`)
)
View Source
var (
	//SnakeCase 单词全部小写并用下划线连接
	SnakeCase URLConvert = com.SnakeCase

	//LowerCaseFirst 小写首字母
	LowerCaseFirst URLConvert = com.LowerCaseFirst

	//PascalCase 帕斯卡命名法
	PascalCase URLRecovery = com.PascalCase

	//UpperCaseFirst 大写首字母
	UpperCaseFirst URLRecovery = strings.Title
)
View Source
var (
	IsMapper = func(t reflect.Type) bool {
		return t == mapperType
	}
	DefaultContextInitial = func(ctx echo.Context, wrp *Wrapper, controller interface{}, actionName string) (err error, exit bool) {
		return
	}
)

Functions

This section is empty.

Types

type After

type After interface {
	After() error
}

After 动态实例中的后置行为

type AfterHandler

type AfterHandler interface {
	After(echo.Context) error
}

AfterHandler 静态实例中的后置行为

type AllowFormat

type AllowFormat interface {
	AllowFormat(urlPath string, extension string) bool
}

type Before

type Before interface {
	Before() error
}

Before 动态实例中的前置行为

type BeforeHandler

type BeforeHandler interface {
	Before(echo.Context) error
}

BeforeHandler 静态实例中的前置行为

type ExitChecker

type ExitChecker interface {
	IsExit() bool
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(h func(echo.Context) error, name string) *Handler

func (*Handler) Handle

func (h *Handler) Handle(c echo.Context) error

func (*Handler) HandleName

func (h *Handler) HandleName() string

type Initer

type Initer interface {
	Init(echo.Context) error
}

Initer 动态实例中的初始化行为

type MVC

type MVC struct {
	Core               *echo.Echo
	Name               string
	TemplateDir        string
	StaticDir          string
	StaticRes          *resource.Static
	RouteTagName       string
	URLConvert         URLConvert  `json:"-" xml:"-"`
	URLRecovery        URLRecovery `json:"-" xml:"-"`
	MaxUploadSize      int64
	RootModuleName     string
	URL                string
	URLs               *URLs
	DefaultMiddlewares []interface{} `json:"-" xml:"-"`
	SessionOptions     *echo.SessionOptions
	Renderer           driver.Driver                                                   `json:"-" xml:"-"`
	FuncMap            map[string]interface{}                                          `json:"-" xml:"-"`
	ContextCreator     func(*echo.Echo) echo.Context                                   `json:"-" xml:"-"`
	ContextInitial     func(echo.Context, *Wrapper, interface{}, string) (error, bool) `json:"-" xml:"-"`
	// contains filtered or unexported fields
}

func New

func New(name string, middlewares ...interface{}) (s *MVC)

New 创建MVC实例

func NewWithContext

func NewWithContext(name string, newContext func(*echo.Echo) echo.Context, middlewares ...interface{}) (s *MVC)

NewWithContext 创建MVC实例

func (*MVC) AddEvent

func (s *MVC) AddEvent(eventName string, handler interface{}) *MVC

func (*MVC) Debug

func (s *MVC) Debug(on bool) *MVC

Debug 开关debug模式

func (*MVC) DelEvent

func (s *MVC) DelEvent(eventName string) *MVC

func (*MVC) Event

func (s *MVC) Event(eventName string, next func(bool), sessions ...interface{}) *MVC

func (*MVC) GoEvent

func (s *MVC) GoEvent(eventName string, next func(bool), sessions ...interface{}) *MVC

func (*MVC) HasModule

func (s *MVC) HasModule(name string) bool

func (*MVC) InitStatic

func (s *MVC) InitStatic() *MVC

InitStatic 初始化静态资源

func (*MVC) LoadConfig

func (s *MVC) LoadConfig(file string, config interface{}) error

LoadConfig 载入confl支持的配置文件

func (*MVC) Module

func (s *MVC) Module(args ...string) *Module

Module 获取模块实例

func (*MVC) ModuleOk

func (s *MVC) ModuleOk(args ...string) (app *Module, ok bool)

ModuleOk 获取模块实例

func (*MVC) Modules

func (s *MVC) Modules(args ...bool) map[string]*Module

func (*MVC) NewModule

func (s *MVC) NewModule(name string, middlewares ...interface{}) *Module

NewModule 创建新模块

func (*MVC) NewRenderer

func (s *MVC) NewRenderer(conf *render.Config, a *Module, funcMap map[string]interface{}) driver.Driver

NewRenderer 新建渲染接口

func (*MVC) NewStatic

func (s *MVC) NewStatic(urlPath string, absPath string, f ...map[string]interface{}) *resource.Static

NewStatic 新建静态资源实例

func (*MVC) NewTemplateEngine

func (s *MVC) NewTemplateEngine(tmplPath string, conf *render.Config) driver.Driver

NewTemplateEngine 新建模板引擎实例

func (*MVC) RootDir

func (s *MVC) RootDir() string

RootDir 网站根目录

func (*MVC) Run

func (s *MVC) Run(args ...interface{})

Run 运行服务

func (*MVC) ServeHTTP

func (s *MVC) ServeHTTP(r engine.Request, w engine.Response)

ServeHTTP HTTP服务执行入口

func (*MVC) SetDomain

func (s *MVC) SetDomain(name string, domain string) *MVC

SetDomain 为模块设置域名

func (*MVC) SetSessionOptions

func (s *MVC) SetSessionOptions(sessionOptions *echo.SessionOptions) *MVC

func (*MVC) SetTheme

func (s *MVC) SetTheme(conf *render.Config) *MVC

SetTheme 设置模板主题

func (*MVC) TemplateMonitor

func (s *MVC) TemplateMonitor() *MVC

TemplateMonitor 模板监控事件

func (*MVC) Theme

func (s *MVC) Theme() string

Theme 当前使用的主题名称

func (*MVC) ThemeDir

func (s *MVC) ThemeDir(args ...string) string

ThemeDir 主题所在文件夹的路径

type Main

type Main interface {
	Main() error
}

Main 动态实例中的行为入口

type Mapper

type Mapper struct{}

Mapper 结构体中定义路由的字段类型

type Module

type Module struct {
	*MVC        `json:"-" xml:"-"`
	Group       *echo.Group   `json:"-" xml:"-"`
	Handler     *echo.Echo    `json:"-" xml:"-"` //指定域名时有效
	Middlewares []interface{} `json:"-" xml:"-"`
	Renderer    driver.Driver `json:"-" xml:"-"`
	Name        string
	Domain      string

	URL string
	Dir string

	// 模块附加信息
	Disabled    int    // 禁用时间戳,为0时为启用状态
	Installed   int    // 安装时间戳,为0时为未安装
	Expired     int    // 过期时间戳,为0时为永不过期
	Author      string // 作者名称
	Website     string // 作者网址
	Email       string // 作者邮箱
	Description string // 简介
	Config      ModuleConfiger

	// 安装和卸载逻辑
	Install   func() error `json:"-" xml:"-"`
	Uninstall func() error `json:"-" xml:"-"`
	// contains filtered or unexported fields
}

func NewModule

func NewModule(name string, domain string, s *MVC, middlewares ...interface{}) (a *Module)

func (*Module) AddHandler

func (a *Module) AddHandler(c interface{}) *Wrapper

AddHandler 登记控制器

func (*Module) C

func (a *Module) C(name string) (c interface{})

C 获取控制器

func (*Module) ClearCachedHandlerNames

func (a *Module) ClearCachedHandlerNames()

func (*Module) ExecAction

func (a *Module) ExecAction(action string, t reflect.Type, v reflect.Value, c echo.Context) (err error)

ExecAction 执行Action的通用方式

func (*Module) InitRenderer

func (a *Module) InitRenderer(conf *render.Config, funcMap map[string]interface{}) *Module

InitRenderer 初始化渲染接口(用于单独对app指定renderer,如不指定,默认会使用Server中Renderer)

func (*Module) Register

func (a *Module) Register(p string, v interface{}, methods ...string) *Module

Register 注册路由:module.Register(`/index`,Index.Index,"GET","POST")

func (*Module) Router

func (a *Module) Router() echo.ICore

func (*Module) SafelyCall

func (a *Module) SafelyCall(fn reflect.Value, args []reflect.Value) (resp []reflect.Value, err error)

SafelyCall invokes `function` in recover block

func (*Module) Use

func (a *Module) Use(args ...interface{}) *Module

Use 批量注册控制器路由

func (*Module) Valid

func (a *Module) Valid() error

func (*Module) Wrapper

func (a *Module) Wrapper(name string) (wp *Wrapper)

Wrapper 获取封装器

type ModuleConfig

type ModuleConfig struct {
	// contains filtered or unexported fields
}

func (*ModuleConfig) Config

func (a *ModuleConfig) Config() interface{}

func (*ModuleConfig) Get

func (a *ModuleConfig) Get(recvFn func(interface{}))

Get usage: var appConf *map[string]string

a.Get(func(conf interface{}){
	if v, y := conf.(*map[string]string); y {
		appConf = v
	}
})

func (*ModuleConfig) Init

func (a *ModuleConfig) Init(config interface{}) ModuleConfiger

func (*ModuleConfig) IsValid

func (a *ModuleConfig) IsValid() bool

func (*ModuleConfig) Set

func (a *ModuleConfig) Set(data string) error

Set usage: var appConf map[string]string a.Set(`{"Name":"webx"}`)

func (*ModuleConfig) SetTemplate

func (a *ModuleConfig) SetTemplate(tmplFile string) ModuleConfiger

func (*ModuleConfig) String

func (a *ModuleConfig) String() string

func (*ModuleConfig) Template

func (a *ModuleConfig) Template() string

type ModuleConfiger

type ModuleConfiger interface {
	Init(conf interface{}) ModuleConfiger
	Set(data string) error
	Get(recvFn func(interface{}))
	Config() interface{}
	IsValid() bool
	String() string
	Template() string                           //获取表单模板名称
	SetTemplate(tmplFile string) ModuleConfiger //获取设置表单模板
}

type StaticIniter

type StaticIniter interface {
	Init(wrp *Wrapper, act string) error
}

type URLConvert

type URLConvert func(string) string

URLConvert 网址转换

type URLRecovery

type URLRecovery func(string) string

URLRecovery 网址还原

type URLs

type URLs struct {
	*MVC `json:"-" xml:"-"`
	// contains filtered or unexported fields
}

func NewURLs

func NewURLs(project string, mvc *MVC) *URLs

func (*URLs) AllowFormat

func (a *URLs) AllowFormat(key string, ext string) (ok bool)

func (*URLs) Build

func (a *URLs) Build(mdl string, ctl string, act string, params ...interface{}) (r string)

func (*URLs) BuildFromPath

func (a *URLs) BuildFromPath(ppath string, args ...map[string]interface{}) (r string)

func (*URLs) Set

func (a *URLs) Set(h interface{}) (pkg string, ctl string, act string)

func (*URLs) SetExtensions

func (a *URLs) SetExtensions(key string, exts []string) *URLs

func (*URLs) SetProjectPath

func (a *URLs) SetProjectPath(projectPath string)

type Wrapper

type Wrapper struct {

	// 实例对象
	Controller     interface{}        `json:"-" xml:"-"`
	RouteRegister  echo.RouteRegister `json:"-" xml:"-"`
	Module         *Module            `json:"-" xml:"-"`
	ControllerName string
	// contains filtered or unexported fields
}

func (*Wrapper) Auto

func (a *Wrapper) Auto(args ...interface{})

Auto 自动注册动态实例的路由:a.Auto()

func (*Wrapper) Exec

func (a *Wrapper) Exec(ctx echo.Context, t reflect.Type, action string) error

func (*Wrapper) HandleName

func (a *Wrapper) HandleName(h interface{}) string

func (*Wrapper) Register

func (a *Wrapper) Register(p string, h interface{}, methods ...string) *Wrapper

Register 路由注册方案1:注册函数(可匿名)或静态实例的成员函数 例如:Register(`/index`,Index.Index,"GET","POST")

func (*Wrapper) RouteMethods

func (a *Wrapper) RouteMethods()

RouteMethods 路由注册方案3:自动注册动态实例内带HTTP方法名后缀的成员函数作为路由

func (*Wrapper) RouteTags

func (a *Wrapper) RouteTags()

RouteTags 路由注册方案2:从动态实例内Mapper类型字段标签中获取路由信息

Directories

Path Synopsis
static
minify
Package cssmin minifies CSS.
Package cssmin minifies CSS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL