webs

package
v0.0.0-...-11fa3e6 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyUser     = "user"
	KeyReqStart = "reqStart"
	KeyTrace    = "trace"
	KeyLang     = "lang"

	KeySqlCount      = "sqlCount"
	KeyRender        = "render"
	KeyCtx           = "ctx"
	KeyIsDebug       = "isDebug"
	KeyServiceCost   = "serviceCost"
	KeyTplStart      = "tplStart"
	KeyTplParseCost  = "tplParseCost"
	KeyTplRenderCost = "tplRenderCost"
	KeyTotalCost     = "totalCost"
	KeyErr           = "err"
	HeaderTrace      = "X-Trace-ID"
)
View Source
const LoginCookieName = "login"
View Source
const UserKey = "currentUser"

Variables

This section is empty.

Functions

func AddSqlCount

func AddSqlCount(ctx context.Context)

AddSqlCount sql 计数加一

func Admin

func Admin(ctx *gin.Context)

func Api

func Api(h func(ctx *gin.Context) (any, error)) gin.HandlerFunc

func GenTraceID

func GenTraceID() string

GenTraceID 生成 traceID

func GetContext

func GetContext(c *gin.Context) context.Context

func GetRender

func GetRender(ctx *gin.Context) types.ReloadableRender

GetRender 从上下文中拿出 Render (SetRender 时注入的)

func GetSqlCount

func GetSqlCount(ctx *gin.Context) int64

func GetUser

func GetUser(ctx *gin.Context) *dto.UserInfo

GetUser 用从 Cookie 解析到的登录信息,去查数据库中用户信息

func I18n

func I18n(c *gin.Context)

I18n 为每个请求决定使用哪种语言

func InitI18n

func InitI18n(defaultLangFs embed.FS)

InitI18n 初始化翻译

func Install

func Install(ctx *gin.Context)

Install 未安装拦截

func LoginInfo

func LoginInfo(ctx *gin.Context)

LoginInfo 中间件 从 Cookie 中获取登录信息

func Render

func Render(tpl string, datas ...gin.H) gin.HandlerFunc

Render 渲染页面

func Response

func Response(result any, err error) gin.H

func SetContext

func SetContext(c *gin.Context, ctx context.Context)

func SetRender

func SetRender(views embed.FS) gin.HandlerFunc

SetRender 设置模板渲染器

func SetUserInfo

func SetUserInfo(ctx *gin.Context, loginInfo *dto.LoginInfo)

SetUserInfo 登录成功时将登录信息设置到缓存和 cookie 中

func Trace

func Trace(c *gin.Context)

Trace 为每个请求设置一个唯一标记

func WithI18n

func WithI18n(ctx context.Context, data gin.H) gin.H

WithI18n 将翻译工具函数等注入到模板变量中

Types

This section is empty.

Jump to

Keyboard shortcuts

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