mvc

package
v0.0.0-...-77cf2aa Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: Apache-2.0 Imports: 16 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandlers

func AddHandlers(ic ...IController)

AddHandlers 将Controller控制器注册到默认的Mvc框架对象中 即是添加路由动作

func AddMainRouter

func AddMainRouter(list ...*MainRouter)

AddMainRouter 默认mvc框架 主节点路由匹配原则注册 目前系统变量支持格式为 `/{ Controller}/{Action}/{id:int}/{who:string}/{allString}`

如果不进行路由注册 默认为/{ Controller}/{Action} router.ControllerActionInfo中 ControllerActionFuncName不用设置 设置了也不会生效

func MapStringToStruct

func MapStringToStruct(i interface{}, data map[string]interface{}) interface{}

MapStringToStruct 字符转类型

func MapStringToStructInReflect

func MapStringToStructInReflect(v reflect.Value, data map[string]interface{}) interface{}

func SetDefaultMvcWebConfig

func SetDefaultMvcWebConfig(webConfig *MvcWebConfig)

func SetStatusCodeHandlers

func SetStatusCodeHandlers(s IStatusCodeController)

SetStatusCodeHandlers 将Controller控制器注册到Mvc框架的定制状态处理程序中 如:404状态自定义 不传使用默认的

Types

type ActionRouter

type ActionRouter struct {
	// 传设置控制器的方法
	ControllerActionFuncName string
	//路由设置  如:/{Controller}/{Action}/{id:int}
	// /home/index/123可以匹配成功
	RouterPattern string

	// 正则表达式匹配
	PatternRe *regexp.Regexp
	// contains filtered or unexported fields
}

ActionRouter 单一动作器路由设置结构体

type Controller

type Controller struct {
	// 响应前端的处理 不建议使用
	Response freefishgo.IResponse
	// 重置控制器路由  必须包含{Action}变量
	ControllerRouter *ControllerRouter
	// 控制器单一方法设置路由
	ActionRouterList []*ActionRouter
	// 和前端一切的数据  都可以通过他获取
	Request *freefishgo.Request

	// 前端传来的数据都可以获取  包括路由格式化的数据  如 /{id:string}  可通过 Query["id"]获取值
	Query map[string]interface{}
	// 模板引擎中变量数据
	Data map[interface{}]interface{}

	// 母版页地址
	LayoutPath string
	//母版页子页面地址
	LayoutSections map[string]string
	// contains filtered or unexported fields
}

Controller http请求逻辑控制器

func (*Controller) Finish

func (c *Controller) Finish()

Finish 控制器结束时调用

func (*Controller) Prepare

func (c *Controller) Prepare()

Prepare 控制器执行前调用

func (*Controller) SkipController

func (c *Controller) SkipController()

SkipController 停止执行控制器

func (*Controller) UseTplPath

func (c *Controller) UseTplPath(tplPath ...string)

UseTplPath 使用模板的路径并启动调用模板

管道中任意地方调用Controller.HttpContext.Response.Write() 方法会失效

不使用路径会用v.ViewsPath/{Controller}/{Action}.fish

多路径只用最后一个

type ControllerRouter

type ControllerRouter struct {
	//路由设置  如:/{Controller}/{Action}/{id:int}
	// /home/index/123可以匹配成功
	RouterPattern string
	// contains filtered or unexported fields
}

ControllerRouter 单一控制器路由设置结构体,路由规则中必须包含`{Action}`变量

type IController

type IController interface {

	// UseTplPath 使用模板
	UseTplPath(tplPath ...string)
	// SkipController 跳过控制器
	SkipController()
	// Prepare http控制器处理前调用方法
	Prepare()
	// Finish http控制器执行后调用方法
	Finish()
	// contains filtered or unexported methods
}

IController 控制器的基本数据结构

type IStatusCodeController

type IStatusCodeController interface {
	IController
	// Error500 http500处理方法
	Error500()
	// NotFind404 http404处理方法
	NotFind404()
	// Forbidden403 http403处理方法
	Forbidden403()
}

IStatusCodeController 响应状态处理接口

type MainRouter

type MainRouter struct {
	//路由设置  如:/{Controller}/{Action}/{id:int}
	// /home/index/123可以匹配成功
	RouterPattern string
	// Controller名称
	HomeController string
	// 动作名称
	IndexAction string
}

MainRouter 主路由

type MvcApp

type MvcApp struct {

	//Server   *http.Server
	Config *MvcWebConfig
	// contains filtered or unexported fields
}

func GetDefaultMvcApp

func GetDefaultMvcApp() *MvcApp

func NewFreeFishMvcApp

func NewFreeFishMvcApp() *MvcApp

NewFreeFishMvcApp 实例化生成一个Mvc对象

func (*MvcApp) AddHandlers

func (mvc *MvcApp) AddHandlers(ic ...IController)

AddHandlers 将Controller控制器注册到Mvc框架对象中 即是添加路由动作

func (*MvcApp) AddMainRouter

func (mvc *MvcApp) AddMainRouter(list ...*MainRouter)

AddMainRouter 主节点路由匹配原则注册 目前系统变量支持格式为 `/{ Controller}/{Action}/{id:int}/{who:string}/{allString}`

如果不进行路由注册 默认为/{ Controller}/{Action} router.ControllerActionInfo中 ControllerActionFuncName不用设置 设置了也不会生效

func (*MvcApp) LastInit

func (mvc *MvcApp) LastInit(cnf *freefishgo.Config)

LastInit 框架注册完成时 进行最后的配置

func (*MvcApp) Middleware

func (mvc *MvcApp) Middleware(ctx *freefishgo.HttpContext, next freefishgo.Next) (c *freefishgo.HttpContext)

Middleware Web服务逻辑处理程序

func (*MvcApp) SetStatusCodeHandlers

func (mvc *MvcApp) SetStatusCodeHandlers(s IStatusCodeController)

SetStatusCodeHandlers 将Controller控制器注册到Mvc框架的定制状态处理程序中 如:404状态自定义 不传使用默认的

type MvcWebConfig

type MvcWebConfig struct {
	// 是否启用开发模式
	IsDevelopment bool
	// html模板引擎变量左标记符号
	TemplateLeft string
	// html模板引擎变量右标记符号
	TemplateRight string
	// html Layout模板引擎变量左标记符号
	LayoutTemplateLeft string
	// html Layout模板引擎变量右标记符号
	LayoutTemplateRight string
	// html模板的父目录
	ViewsPath string
	// 静态文件地址
	StaticDir string
	// contains filtered or unexported fields
}

func NewWebConfig

func NewWebConfig() *MvcWebConfig

NewWebConfig 实例化一个 MvcWebConfig

type StatusCodeController

type StatusCodeController struct {
	Controller
}

StatusCodeController http响应状态处理

func (*StatusCodeController) Error500

func (s *StatusCodeController) Error500()

Error500 http 500错误处理

func (*StatusCodeController) Forbidden403

func (s *StatusCodeController) Forbidden403()

Forbidden403 http 403处理

func (*StatusCodeController) NotFind404

func (s *StatusCodeController) NotFind404()

NotFind404 http 404处理

Jump to

Keyboard shortcuts

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