lolly/internal/utils/internal.go

34 lines
887 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package utils 提供通用的工具函数和辅助类型。
//
// 包含内部工具函数,用于处理内部逻辑。
//
// 作者xfy
package utils
import "github.com/valyala/fasthttp"
const (
// InternalRedirectKey 内部重定向标记
InternalRedirectKey = "__internal_redirect__"
)
// SetInternalRedirect 标记请求为内部重定向
func SetInternalRedirect(ctx *fasthttp.RequestCtx, targetPath string) {
ctx.SetUserValue(InternalRedirectKey, targetPath)
}
// IsInternalRedirect 检查是否为内部重定向
func IsInternalRedirect(ctx *fasthttp.RequestCtx) bool {
return ctx.UserValue(InternalRedirectKey) != nil
}
// GetInternalRedirectPath 获取内部重定向目标路径
func GetInternalRedirectPath(ctx *fasthttp.RequestCtx) string {
if v := ctx.UserValue(InternalRedirectKey); v != nil {
if s, ok := v.(string); ok {
return s
}
}
return ""
}