修改引用头部,不是用ctx

This commit is contained in:
ayflying
2025-03-19 17:41:23 +08:00
parent 14de836089
commit 5c45ddb80b
4 changed files with 41 additions and 6 deletions

View File

@@ -2,7 +2,6 @@ package act{id}
import (
service2 "github.com/ayflying/utility_go/service"
"github.com/gogf/gf/v2/os/gctx"
)
type sAct{id} struct {
@@ -14,7 +13,7 @@ func New() *sAct{id} {
var (
ActId = {id}
ctx = gctx.New()
Name = ""
)
type Data struct {

View File

@@ -9,7 +9,7 @@ type s{name} struct {
}
var (
ctx = gctx.New()
)
func New() *s{name} {

View File

@@ -62,9 +62,9 @@ func MiddlewareAdmin(r *ghttp.Request) {
ip := r.GetClientIp()
r.SetCtxVar("ip", ip)
get := r.Cookie.Get("uid")
getUid := r.Cookie.Get("uid")
if get == nil {
if getUid == nil {
//调试模式允许不验证用户名
debug, _ := g.Cfg().GetWithEnv(nil, "debug")
if !debug.Bool() {
@@ -82,7 +82,13 @@ func MiddlewareAdmin(r *ghttp.Request) {
}
uid := get.Int()
uid := getUid.Int()
//获取所有请求的信息
get := r.GetRequestMapStrStr()
if _, ok := get["uid"]; ok {
r.SetCtxVar("uid", get["uid"])
}
r.Middleware.Next()

View File

@@ -223,3 +223,33 @@ func ReverseSlice[T comparable](s []T) []T {
}
return s
}
// 道具数量合并
func (m *tools) ItemsMerge(_items ...[][]int64) [][]int64 {
var items [][]int64
for _, v := range _items {
items = append(items, v...)
}
if len(items) == 0 {
return [][]int64{}
}
var temp = make(map[int64]int64)
for _, v := range items {
if len(v) < 2 {
g.Log().Errorf(ctx, "分解的物品格式不对:%v", v)
continue
}
if _, ok := temp[v[0]]; !ok {
temp[v[0]] = 0
}
temp[v[0]] += v[1]
}
items = make([][]int64, len(temp))
i := 0
for k, v := range temp {
items[i] = []int64{k, v}
i++
}
return items
}