app

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Translate

func Translate(err error) []string

将validator错误信息翻译成中文

Types

type Action

type Action map[IController]string

type App

type App struct {
	Engine  *gin.Engine
	Router  RouterGroup
	FuncMap template.FuncMap
	// contains filtered or unexported fields
}

func NewApp

func NewApp(views ...fs.FS) *App

func (*App) Bind

func (app *App) Bind(abstract string, closure contracts.ServiceFunc, share ...bool)

每次实例化

func (*App) GetEngine

func (app *App) GetEngine() *gin.Engine

func (*App) GetRoutesGroup added in v0.0.6

func (app *App) GetRoutesGroup() (result interface{})

获取路由数组,数组每个元素都是一个路由组

func (*App) GetRoutesTree added in v0.0.6

func (app *App) GetRoutesTree() interface{}

获取路由树

func (*App) InjectApp

func (app *App) InjectApp(providers interface{}) interface{}

往指定的结构体注入app对象

func (*App) Make

func (app *App) Make(abstract string) interface{}

创建实例

func (*App) Middlewares

func (app *App) Middlewares(middlewares interface{})

调用默认的全局中间件

func (*App) Name

func (app *App) Name() string

获取应用名称

func (*App) NoRoute

func (app *App) NoRoute(handlers ...interface{})

页面404

func (*App) RegistEvent

func (app *App) RegistEvent(listens interface{})

注册事件

func (*App) Register

func (app *App) Register(providers interface{})

func (*App) Run

func (app *App) Run(addr ...string)

开始程序

func (*App) SetFuncMap

func (app *App) SetFuncMap(funcMap template.FuncMap)

设置模板函数

func (*App) SetHTMLTemplate

func (app *App) SetHTMLTemplate(views fs.FS)

将打包的模板文件整理并且可以嵌套使用

func (*App) Singleton

func (app *App) Singleton(abstract string, closure contracts.ServiceFunc)

只实例化一次

func (*App) Use

func (app *App) Use(middlewares ...interface{})

使用中间件

type Context

type Context struct {
	*gin.Context
	// contains filtered or unexported fields
}

func (*Context) Auth

func (c *Context) Auth(guard ...string) contracts.IAuth

用户登录

func (*Context) HTML

func (c *Context) HTML(code int, name string, obj interface{})

重写HTML,加入share

func (*Context) IsAjax added in v0.1.8

func (c *Context) IsAjax() (isAjax bool)

判断是否是ajax请求

func (*Context) NewPagination

func (c *Context) NewPagination(total int64) *pagination

分页

func (*Context) Param added in v0.1.2

func (c *Context) Param(key string) string

重写param函数,获取带.html, .htm, .xhtml等后缀的参数

func (*Context) ParseParams

func (c *Context) ParseParams(key string) map[string]string

对含有*号的路由转为参数 如 /user/*action ( /user/region/china/page/3 map[string]string{"region":"china", "page":"3"})

func (*Context) Share

func (c *Context) Share(key string, data interface{})

共享视图数据

func (*Context) Shared

func (c *Context) Shared(key string) interface{}

获取共享数据

type Controller

type Controller struct {
	App contracts.IApplication
}

func (*Controller) Create

func (ctrl *Controller) Create(c *Context)

创建

func (*Controller) Destroy

func (ctrl *Controller) Destroy(c *Context)

删除指定数据

func (*Controller) Edit

func (ctrl *Controller) Edit(c *Context)

编辑

func (*Controller) Index

func (ctrl *Controller) Index(c *Context)

列表

func (*Controller) Init

func (ctrl *Controller) Init(c *Context)

初始化,在其它方法之前调用

func (*Controller) NotFound

func (ctrl *Controller) NotFound(c *Context)

func (*Controller) Show

func (ctrl *Controller) Show(c *Context)

显示指定数据

func (*Controller) Store

func (ctrl *Controller) Store(c *Context)

创建保存

func (*Controller) Update

func (ctrl *Controller) Update(c *Context)

编辑保存

type H

type H = gin.H

避免在控制器引入gin包,重定义gin.H

type HandlerFunc

type HandlerFunc = func(*Context)

type IController

type IController interface {
	Init(*Context)
	Index(*Context)
	Show(*Context)
	Create(*Context)
	Store(*Context)
	Edit(*Context)
	Update(*Context)
	Destroy(*Context)
}

restful api 控制器接口

type IRouter

type IRouter interface {
	IRoutes
	Group(string, ...interface{}) *RouterGroup
}

type IRoutes

type IRoutes interface {
	Use(...interface{}) IRoutes
	Handle(string, string, ...interface{}) IRoutes
	Any(string, ...interface{}) IRoutes
	Get(string, ...interface{}) IRoutes
	Post(string, ...interface{}) IRoutes
	Delete(string, ...interface{}) IRoutes
	Patch(string, ...interface{}) IRoutes
	Put(string, ...interface{}) IRoutes
	Options(string, ...interface{}) IRoutes
	Head(string, ...interface{}) IRoutes
}

type RouterGroup

type RouterGroup struct {
	App     *App
	GRouter *gin.RouterGroup
	Comment string
	// contains filtered or unexported fields
}

func (*RouterGroup) Any

func (r *RouterGroup) Any(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Delete

func (r *RouterGroup) Delete(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Get

func (r *RouterGroup) Get(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Group

func (r *RouterGroup) Group(relativePath string, args ...interface{}) *RouterGroup

func (*RouterGroup) Handle

func (r *RouterGroup) Handle(httpMethod, relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Head

func (r *RouterGroup) Head(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Options

func (r *RouterGroup) Options(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Patch

func (r *RouterGroup) Patch(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Post

func (r *RouterGroup) Post(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Put

func (r *RouterGroup) Put(relativePath string, args ...interface{}) IRoutes

func (*RouterGroup) Resource

func (r *RouterGroup) Resource(relativePath string, ctrl IController, comment string)

func (*RouterGroup) Use

func (r *RouterGroup) Use(args ...interface{}) IRoutes

Jump to

Keyboard shortcuts

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