mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 19:53:55 +08:00
This commit is contained in:
@@ -34,7 +34,7 @@ func Get(ctx context.Context) *model.Context {
|
||||
func SetUser(ctx context.Context, user *model.Identity) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetUser, c == nil ")
|
||||
g.Log().Warning(ctx, "contexts.SetUser, c == nil ")
|
||||
return
|
||||
}
|
||||
c.User = user
|
||||
@@ -44,7 +44,7 @@ func SetUser(ctx context.Context, user *model.Identity) {
|
||||
func SetResponse(ctx context.Context, response *model.Response) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetResponse, c == nil ")
|
||||
g.Log().Warning(ctx, "contexts.SetResponse, c == nil ")
|
||||
return
|
||||
}
|
||||
c.Response = response
|
||||
@@ -54,22 +54,12 @@ func SetResponse(ctx context.Context, response *model.Response) {
|
||||
func SetModule(ctx context.Context, module string) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetModule, c == nil ")
|
||||
g.Log().Warning(ctx, "contexts.SetModule, c == nil ")
|
||||
return
|
||||
}
|
||||
c.Module = module
|
||||
}
|
||||
|
||||
// SetTakeUpTime 设置请求耗时
|
||||
func SetTakeUpTime(ctx context.Context, takeUpTime int64) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetTakeUpTime, c == nil ")
|
||||
return
|
||||
}
|
||||
c.TakeUpTime = takeUpTime
|
||||
}
|
||||
|
||||
// GetUser 获取用户信息
|
||||
func GetUser(ctx context.Context) *model.Identity {
|
||||
c := Get(ctx)
|
||||
@@ -120,7 +110,7 @@ func GetModule(ctx context.Context) string {
|
||||
func SetAddonName(ctx context.Context, name string) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetAddonName, c == nil ")
|
||||
g.Log().Warning(ctx, "contexts.SetAddonName, c == nil ")
|
||||
return
|
||||
}
|
||||
Get(ctx).AddonName = name
|
||||
@@ -143,3 +133,35 @@ func GetAddonName(ctx context.Context) string {
|
||||
}
|
||||
return Get(ctx).AddonName
|
||||
}
|
||||
|
||||
// SetData 设置额外数据
|
||||
func SetData(ctx context.Context, k string, v interface{}) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetData, c == nil ")
|
||||
return
|
||||
}
|
||||
Get(ctx).Data[k] = v
|
||||
}
|
||||
|
||||
// SetDataMap 设置额外数据
|
||||
func SetDataMap(ctx context.Context, vs g.Map) {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
g.Log().Warning(ctx, "contexts.SetData, c == nil ")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range vs {
|
||||
Get(ctx).Data[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// GetData 获取额外数据
|
||||
func GetData(ctx context.Context) g.Map {
|
||||
c := Get(ctx)
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.Data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user