controller

package
v0.0.0-...-212a885 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 14 Imported by: 3

Documentation

Overview

* @Author: Wangjun * @Date: 2021-05-15 22:43:19 * @LastEditTime: 2021-07-20 11:34:01 * @LastEditors: Wangjun * @Description: * @FilePath: \golib\autoroute\controller\auth.go * hnxr

* @Author: Wangjun * @Date: 2021-05-15 22:43:19 * @LastEditTime: 2021-11-25 10:10:14 * @LastEditors: Wangjun * @Description: * @FilePath: \xrcalcd:\go\src\gitee.com\haodreams\golib\autoroute\controller\libs.go * hnxr

* @Author: Wangjun * @Date: 2021-05-15 22:43:19 * @LastEditTime: 2024-04-01 14:04:28 * @LastEditors: wangjun haodreams@163.com * @Description: * @FilePath: \golib\autoroute\controller\param.go * hnxr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(c *gin.Context, msg string)

Error ...

func ErrorWithCode

func ErrorWithCode(c *gin.Context, msg string, code int)

ErrorWithCode ...

func IsPost

func IsPost(c *gin.Context) bool

IsPost 是否是post方法提交

func Msg

func Msg(c *gin.Context, msg string)

Msg ...

func SetNeedAuthCallback

func SetNeedAuthCallback(cb func(*gin.Context) (interface{}, error))

SetNeedAuthCallback 设置认证回调函数, gin.H

Types

type AuthController

type AuthController struct {
	Controller
	Sess *minauth.Session
}

AuthController 认证控制器

func (*AuthController) Setup

func (m *AuthController) Setup(c *gin.Context, controllerName string) (err error)

Setup 初始化设置

type Controller

type Controller struct {
	*gin.Context
	ControllerName string //控制器名称
	ActionName     string //事件名称
	Map            gin.H
	// contains filtered or unexported fields
}

Controller 控制器

func (*Controller) AddCookie

func (m *Controller) AddCookie(name, value string, maxAge int)

AddCookie = SetCookie

func (*Controller) Data

func (m *Controller) Data(data interface{})

MsgData 正常通知消息

func (*Controller) DataWithCode

func (m *Controller) DataWithCode(data interface{}, msg string, code ...int)

DataWithMsg 返回数据包

func (*Controller) DataWithMsg

func (m *Controller) DataWithMsg(data interface{}, msg string, code ...int)

DataWithMsg 返回数据包 Deprecated: this function simply calls DataWithCode

func (*Controller) DataWithStatusCode

func (m *Controller) DataWithStatusCode(data interface{}, msg string, codes ...int)

DataWithMsg 返回数据包,并指定code为返回状态码

func (*Controller) Display

func (m *Controller) Display(url ...string)

Display 显示

func (*Controller) Error

func (m *Controller) Error(msg string)

Error 错误通知消息

func (*Controller) ErrorBad

func (m *Controller) ErrorBad(msg string)

Error 错误通知消息

func (*Controller) ErrorWithCode

func (m *Controller) ErrorWithCode(msg string, code int)

ErrorWithCode ...

func (*Controller) GetPage

func (m *Controller) GetPage() (page, limit int)

GetPage 获取分页位置

func (*Controller) GetPageFromMap

func (m *Controller) GetPageFromMap(mp map[string]string) (page, limit int)

GetPageFromMap .

func (*Controller) GetPagePosition

func (m *Controller) GetPagePosition(total int) (begin, end int)

GetPagePosition 获取合理的位置 end = 0 表示无效

func (*Controller) GetParam

func (m *Controller) GetParam() *Param

GetParam 获取参数属性

func (*Controller) IsPost

func (m *Controller) IsPost() bool

IsPost 是否是post方法提交

func (*Controller) JSON

func (m *Controller) JSON(code int, obj any)

func (*Controller) Msg

func (m *Controller) Msg(msg string)

Msg 正常通知消息

func (*Controller) MsgData

func (m *Controller) MsgData(data interface{})

MsgData 正常通知消息 Deprecated: this function simply calls DataWithCode

func (*Controller) Page

func (m *Controller) Page(array interface{}, callback func(interface{}) interface{})

Page 显示指定页面的数据 array 传入指定的数组

func (*Controller) PageMapJSON

func (m *Controller) PageMapJSON(array interface{}, mp map[string]string, callback func(interface{}) interface{}) ([]byte, error)

PageMapJSON .

func (*Controller) QueryDB

func (m *Controller) QueryDB(db *gorm.DB, out interface{}, where string)

QueryDB 查询数据库 根据结构体自动生成 out 是结构体数组的指针 users=make([]*User, 0) out=&users

func (*Controller) RecvFile

func (c *Controller) RecvFile(path string) (size int64, fileName string, err error)

func (*Controller) Response

func (m *Controller) Response(data interface{})

Response 回复json消息

func (*Controller) Rows

func (m *Controller) Rows(count int, rows interface{}, msg string, code ...int)

Rows ... {"code":500,"count":0,"data":[], "msg":"` + emsg + `"}`))

func (*Controller) RowsJSON

func (m *Controller) RowsJSON(count int, rows interface{}, msg string, code ...int) ([]byte, error)

RowsJSON .

func (*Controller) Setup

func (m *Controller) Setup(c *gin.Context, controllerName string) (err error)

Setup 初始化设置

type Param

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

Param 自动读取参数

func NewParam

func NewParam(c *gin.Context) *Param

NewParam 新参数

func (*Param) GetBool

func (m *Param) GetBool(key string) bool

GetBool 获取bool数据

func (*Param) GetFloat

func (m *Param) GetFloat(key string) (float64, error)

GetFloat 获取float64数据

func (*Param) GetInt

func (m *Param) GetInt(key string) (int, error)

GetInt 获取INT数据

func (*Param) GetInt64

func (m *Param) GetInt64(key string) (int64, error)

GetInt64 获取INT数据

func (*Param) GetMap

func (m *Param) GetMap() map[string]string

GetMap 获取全部参数

func (*Param) GetString

func (m *Param) GetString(key string) string

GetString 获取字符串

func (*Param) GetTrimString

func (m *Param) GetTrimString(key string) string

GetTrimString 获取去掉2边空格后的字符串

func (*Param) Set

func (m *Param) Set(key, value string)

Set 设置键

type RsponseBody

type RsponseBody struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

应答的数据结构

Jump to

Keyboard shortcuts

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