router

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const CaptchaID = "captcha"

Variables

This section is empty.

Functions

func SwitchDebug

func SwitchDebug(w http.ResponseWriter, r *http.Request)

SwitchDebug 切换调试模式开关

Types

type ErrPageFunc

type ErrPageFunc func(w http.ResponseWriter, resp *route.ErrorResp)

type LoginInfo

type LoginInfo struct {
	LoginTime     time.Time // 登录时间
	IsLogin       bool      // 是否登录
	UserId        int       // 用户ID
	User          string    // 用户名
	IsManage      bool      // 是否管理员
	DemoUser      bool      // 是否演示用户
	RsaPrivateKey []byte    //ras 私钥
	RsaPublickKey []byte    // rsa 公钥
}

func (LoginInfo) QueryIsManage

func (i LoginInfo) QueryIsManage() func(db *gorm.DB) *gorm.DB

type Router

type Router struct {
	Default                string `ini:"default" json:"default" yaml:"default"`
	Root                   string `ini:"root" json:"root" yaml:"root"`
	HttpCache              bool   `ini:"http_cache" json:"http_cache" yaml:"http_cache"`
	HttpCacheMaxAge        string `ini:"http_cache_max_age" json:"http_cache_max_age" yaml:"http_cache_max_age"`
	UnauthorizedRespMethod int    `ini:"unauthorized_resp_method" json:"unauthorized_resp_method" yaml:"unauthorized_resp_method"` // 未登录响应方法 默认为 401,302 表示自动重定向到登录页面
	SessionLoginName       string `ini:"session_login_name" json:"session_login_name" yaml:"session_login_name"`                   // 系统中,用于在session中存储登录信息的key

	// cookie相关配置
	CookiePath     string `ini:"cookie_path" json:"cookie_path" yaml:"cookie_path"`
	CookieDomain   string `ini:"cookie_domain" json:"cookie_domain" yaml:"cookie_domain"`
	CookieSecure   bool   `ini:"cookie_secure" json:"cookie_secure" yaml:"cookie_secure"`
	CookieHttpOnly bool   `ini:"cookie_http_only" json:"cookie_http_only" yaml:"cookie_http_only"`

	Error        ErrPageFunc // 错误页面处理函数
	ErrorWithLog ErrPageFunc // 错误页面处理函数

	IsLogin                bool             // 是否登录
	LoginPath              string           // 登录页面
	HomePage               string           //首页
	UnLoginPath            map[string]bool  // 免授权页面
	UnLoginPathRegexp      []*regexp.Regexp // 免授权页面正则
	MustLoginPath          map[string]bool  //必须登录才能访问的页面
	MustLoginPathRegexp    []*regexp.Regexp // 必须登录才能访问的页面正则
	DisableLoginPath       map[string]bool  // 登录状态下不能访问的页面
	DisableLoginPathRegexp []*regexp.Regexp // 登录状态下不能访问的页面正则
	ManagePage             map[string]bool  // 管理员访问
	ManagePageRegexp       []*regexp.Regexp
	// contains filtered or unexported fields
}

func (*Router) BeforeAction

func (ro *Router) BeforeAction(w http.ResponseWriter, r *http.Request) bool

BeforeAction 所有应用前置操作 Deprecated: 请使用 http server 中间件模式

func (*Router) Captcha deprecated

func (ro *Router) Captcha(w http.ResponseWriter, r *http.Request)

Deprecated: 请使用captcha.Text

func (*Router) DelCookie deprecated

func (ro *Router) DelCookie(w http.ResponseWriter, k, path string)

Deprecated: 请使用 github.com/helays/utils/v2/net/http/cookiekit.DelCookie

func (*Router) GetSession

func (ro *Router) GetSession() *session.Manager

func (*Router) Index

func (ro *Router) Index(w http.ResponseWriter, r *http.Request)
if ro.HttpCache {
	w.Header().Set("cache-control", "max-age="+ro.HttpCacheMaxAge)
	if len(files) == 1 {
		fileInfo, _ := files[0].Stat()
		w.Header().Set("last-modified", fileInfo.ModTime().Format(time.RFC822))
	}
}

上面的后续待定 Deprecated: 请使用route.Index

func (*Router) Middleware

func (ro *Router) Middleware(w http.ResponseWriter, r *http.Request, f func(w http.ResponseWriter, r *http.Request, ro *Router))

Middleware 中间件 Deprecated: 请使用 http server 中间件模式

func (*Router) Play deprecated

func (ro *Router) Play(w http.ResponseWriter, r *http.Request, fname string, args ...any)

Deprecated: 请使用 route.FilePlay 或者 route.FileDownload

func (*Router) SetCookie deprecated

func (ro *Router) SetCookie(w http.ResponseWriter, k, value, path string)

Deprecated: 请使用 github.com/helays/utils/v2/net/http/cookiekit.SetCookie

func (*Router) SetDev

func (ro *Router) SetDev(dev bool)

func (*Router) SetSession

func (ro *Router) SetSession(sessionManager *session.Manager)

func (*Router) SetStaticEmbedFs

func (ro *Router) SetStaticEmbedFs(p string, embedFS *embed.FS, prefix ...string)

SetStaticEmbedFs 设置内置 embedFS

Jump to

Keyboard shortcuts

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