init: taotie-api 项目初始化

This commit is contained in:
2026-05-16 00:14:19 +08:00
commit eb15ef4b87
33 changed files with 1746 additions and 0 deletions

42
utils/sctx/sctx.go Normal file
View File

@@ -0,0 +1,42 @@
package sctx
import (
"context"
"github.com/gin-gonic/gin"
)
type MyKey string
const CurrentKey MyKey = "taotie"
type CurrentUser struct {
UserId string
UserName string
TenantId string
}
func SetCurrentUser(ctx context.Context, cuser *CurrentUser) context.Context {
if c, ok := ctx.(*gin.Context); ok {
c.Set(CurrentKey, cuser)
return c
}
return context.WithValue(ctx, CurrentKey, cuser)
}
func GetCurrentUser(ctx context.Context) *CurrentUser {
if c, ok := ctx.(*gin.Context); ok {
if user, ok := c.Get(CurrentKey); ok {
if cuser, ok := user.(*CurrentUser); ok {
return cuser
}
}
}
if cuser, ok := ctx.Value(CurrentKey).(*CurrentUser); ok {
return cuser
}
return nil
}