# Functions
AccountInfo 从给定的上下文(context.Context)中提取账户信息。 如果上下文为空或上下文中没有找到有效的账户信息,则返回一个默认的 AccountInfo 结构体。
参数: - ctx: context.Context,包含账户信息的上下文
返回值: - info: structs.AccountInfo,从上下文中提取的账户信息
使用示例:
ctx := context.WithValue(context.Background(), AccountInfoKey, &structs.AccountInfo{ ID: "12345", Name: "Alice", }) account := AccountInfo(ctx) if account.Validate() { // 从上下文获取用户信息失败,可能没有调用middleware return } fmt.Println(account.ID, account.Name) // 输出: 12345 Alice.
Android 判断平台是否为 Android.
No description provided by the author
AppType 根据给定的 context 获取应用类型(app、miniapp 或 web)。 它从 context 中提取存储的 AppTypeKey 值,并尝试将其转换为 TAppType。.
Business: 从上下文中获取当前业务 @param ctx: 上下文 前置依赖: middleware.BusinessMiddleware.
CN 判断当前 IDC(Internet Data Center)是否位于北京 返回值: - true:当前 IDC 是北京 IDC - false:当前 IDC 不是北京 IDC
示例:
if CN() { fmt.Println("当前 IDC 在北京") }.
Device 从上下文中获取设备信息,返回对应的 Device 类型.
IOS 判断平台是否为 IOS.
Ipad 判断平台是否为 iPadOS.
IPad 判断设备是否为 iPad.
Linux 判断平台是否为 Linux.
Mac 判断平台是否为 MacOS.
No description provided by the author
PC 判断设备是否为个人电脑.
Phone 判断设备是否为手机.
No description provided by the author
Prod 判断当前环境是否为生产环境(Prod)。 该函数通过 Env() 获取当前环境变量,并与 EnvProd 进行比较。
返回值: - bool: 如果当前环境为生产环境,则返回 true,否则返回 false。
使用示例:
if Prod() { fmt.Println("当前是生产环境") }.
RF 判断当前 IDC(Internet Data Center)是否位于 RF 机房 返回值: - true:当前 IDC 是 RF 机房 - false:当前 IDC 不是 RF 机房
示例:
if RF() { fmt.Println("当前 IDC 在 RF 机房") }.
Test 判断当前环境是否为测试环境(Test)。 该函数通过 Env() 获取当前环境变量,并与 EnvTest 进行比较。
返回值: - bool: 如果当前环境为测试环境,则返回 true,否则返回 false。
使用示例:
if Test() { fmt.Println("当前是测试环境") }.
TestSetAccountInfo:justForTest.
No description provided by the author
No description provided by the author
Windows 判断平台是否为 Windows.
# Constants
AccountInfoKey: 用户信息,请求头&上下文中携带用户信息.
No description provided by the author
No description provided by the author
可选的,表示未知类型.
No description provided by the author
AppTypeKey: 请求头&上下文中携带用户App类型信息.
BusinessKey: 请求头中携带业务信息.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeviceKey: 请求头&上下文中携带设备信息.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
EnvKey: 环境变量中标识服务所处环境.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IdcKey: 环境变量中标识服务所处idc.
PlatformKey: 请求头&上下文中携带平台信息.
RouterKey: 请求头中携带路由信息, 用于AB分组.
VersionKey: 请求头&上下文中携带客户端版本信息.
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author