chore: 初始开源发布

iotlcm-openapi:对外 OpenAPI 网关(V3 接口 + 旧版兼容接口)。

- Go module:iotlcm-openapi → git.5iot.com/iotlcm-public/iotlcm-openapi(178 文件)
- 凭据与地址脱敏:JWT signingKey、MySQL DSN、Redis 口令、
  RabbitMQ DSN 全部改为 ${*} 占位;私网 IP → 文档地址段
- 7 处真实手机号 → 合法 11 位编造号
- 启动 banner 统一 IOTLCM 方块字 + 社区惯例署名
- 移除内部资产:CI 触发器
- Dockerfile 改用公共基础镜像,移除 GOPRIVATE 内网设置
- README 重写(原为 GoFrame 模板占位文案),补 Apache-2.0 LICENSE,
  LF 行尾 + .gitattributes
This commit is contained in:
MiFaZhan
2026-10-23 14:15:47 +08:00
commit 88dfe5c640
482 changed files with 34475 additions and 0 deletions
+224
View File
@@ -0,0 +1,224 @@
// Package contexts
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package contexts
import (
"context"
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/model"
"slices"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type ContextKey struct {
name string
}
var contextKey = &ContextKey{
name: consts.ContextKey,
}
// Init初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
func Init(r *ghttp.Request, customCtx *model.Context) {
r.SetCtxVar(contextKey, customCtx)
}
// Set设置本地上下文
func Set(ctx context.Context, customCtx *model.Context) context.Context {
ctx = context.WithValue(ctx, contextKey, customCtx)
return ctx
}
// Get 获取上下文变量;
func Get(ctx context.Context) *model.Context {
customCtx, ok := ctx.Value(contextKey).(*model.Context)
if !ok {
return nil
}
return customCtx
}
// Set 设置上下文变量
func SetUser(ctx context.Context, user *model.Identity) {
customCtx := Get(ctx)
customCtx.User = user
}
// GetUser 获取上下文变量中的用户信息
func GetUser(ctx context.Context) *model.Identity {
customCtx := Get(ctx)
if customCtx == nil {
return nil
}
return customCtx.User
}
// GetUserId 获取上下文变量中的用户ID
func GetUserId(ctx context.Context) int64 {
user := GetUser(ctx)
if user == nil {
return 0
}
return user.ID
}
// GetUserUuid 获取上下文变量中的用户UUID
func GetUserUuid(ctx context.Context) string {
user := GetUser(ctx)
if user == nil {
return ""
}
return user.UUID
}
// GetUserName 获取上下文变量中的用户名
func GetUserName(ctx context.Context) string {
user := GetUser(ctx)
if user == nil {
return ""
}
return user.Username
}
// GetNickName 获取上下文变量中的用户昵称
func GetNickName(ctx context.Context) string {
user := GetUser(ctx)
if user == nil {
return ""
}
return user.NickName
}
// GetDeptId 获取上下文变量中的部门ID
func GetDeptId(ctx context.Context) int64 {
user := GetUser(ctx)
if user == nil {
return 0
}
g.Log().Debug(ctx, user.DeptId)
return user.DeptId
}
// GetTenantId 获取上下文变量中的租户ID
func GetTenantId(ctx context.Context) string {
user := GetUser(ctx)
if user == nil {
return ""
}
return user.TenantId
}
// GetRoles 获取上下文变量中的角色列表
func GetRoles(ctx context.Context) []model.Role {
user := GetUser(ctx)
if user == nil {
return nil
}
return user.Roles
}
// GetLoginAt 获取上下文变量中的登录时间
func GetLoginAt(ctx context.Context) int64 {
user := GetUser(ctx)
if user == nil {
return 0
}
return user.LoginAt
}
// IsSystemTenant 判断是否是系统租户
func IsSystemTenant(ctx context.Context) bool {
tenantId := GetTenantId(ctx)
return tenantId == consts.DefaultSystemTenantCode
}
// IsSuperAdmin 判断是否是超级管理员角色
func IsSuperAdmin(ctx context.Context) bool {
roles := GetRoles(ctx)
return slices.ContainsFunc(roles, func(role model.Role) bool {
return role.RoleId == consts.SuperAdminRoleId
})
}
func IsWebSocket(ctx context.Context) bool {
customCtx := Get(ctx)
if customCtx == nil {
return false
}
return customCtx.IsWebSocket
}
func SetIsWebSocket(ctx context.Context, isWebSocket bool) {
customCtx := Get(ctx)
if customCtx == nil {
return
}
customCtx.IsWebSocket = isWebSocket
g.Log().Debugf(ctx, "SetIsWebSocket: %v", isWebSocket)
}
// GetAccessCodeList 获取上下文变量中的访问码列表
func GetAccessCodeList(ctx context.Context) []string {
user := GetUser(ctx)
if user == nil {
return nil
}
if len(user.AccessCodeList) == 0 {
return nil
}
return user.AccessCodeList
}
func GetDataValue(ctx context.Context, key string) interface{} {
customCtx := Get(ctx)
if customCtx == nil {
return nil
}
if customCtx.Data == nil {
return nil
}
value, ok := customCtx.Data[key]
if !ok {
return nil
}
return value
}
func SetDataValue(ctx context.Context, key string, value interface{}) {
customCtx := Get(ctx)
if customCtx == nil {
return
}
if customCtx.Data == nil {
customCtx.Data = make(g.Map)
}
customCtx.Data[key] = value
}
func GetAgentUser(ctx context.Context) *model.BaseClaimsApi {
customCtx := Get(ctx)
g.Log().Debug(ctx, customCtx)
if customCtx == nil {
return nil
}
return customCtx.AgentUser
}
func GetAgentDeptId(ctx context.Context) int64 {
agentUser := GetAgentUser(ctx)
if agentUser == nil {
return 0
}
return agentUser.DeptId
}
func GetDeptKey(ctx context.Context) string {
agentUser := GetAgentUser(ctx)
if agentUser == nil {
return ""
}
return agentUser.DeptKey
}