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:
@@ -0,0 +1,115 @@
|
||||
package bcache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/library/cache"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-openapi/internal/library/mcache"
|
||||
"time"
|
||||
)
|
||||
|
||||
const apiAuthLocalBackfillTTL = 6 * time.Hour
|
||||
|
||||
// SetApiAuthToken 存储接口认证长令牌,先写本地内存缓存,再写共享缓存。
|
||||
func SetApiAuthToken(ctx context.Context, uuid string, token string, timeout time.Duration) (err error) {
|
||||
if uuid == "" {
|
||||
return errors.New("api auth token uuid invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthToken, uuid)
|
||||
if err = mcache.Set(ctx, key, token, timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = cache.Instance().Set(ctx, key, token, timeout); err != nil {
|
||||
_ = mcache.Remove(ctx, key)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetApiAuthToken 获取接口认证长令牌,优先读取本地内存缓存。
|
||||
func GetApiAuthToken(ctx context.Context, uuid string) (token string, err error) {
|
||||
if uuid == "" {
|
||||
return "", errors.New("api auth token uuid invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthToken, uuid)
|
||||
t, err := mcache.Instance().Get(ctx, key)
|
||||
if err == nil && !t.IsNil() {
|
||||
return t.String(), nil
|
||||
}
|
||||
|
||||
t, err = cache.Instance().Get(ctx, key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !t.IsNil() {
|
||||
_ = mcache.Set(ctx, key, t.String(), apiAuthLocalBackfillTTL)
|
||||
return t.String(), nil
|
||||
}
|
||||
return "", errors.New("api auth token not found")
|
||||
}
|
||||
|
||||
// DelApiAuthToken 删除接口认证长令牌,先删本地内存缓存,再删共享缓存。
|
||||
func DelApiAuthToken(ctx context.Context, uuid string) (err error) {
|
||||
if uuid == "" {
|
||||
return errors.New("api auth token uuid invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthToken, uuid)
|
||||
if err = mcache.Remove(ctx, key); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = cache.Instance().Remove(ctx, key)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetApiAuthActiveToken 设置机构维度的当前有效令牌索引。
|
||||
func SetApiAuthActiveToken(ctx context.Context, deptId int64, uuid string, timeout time.Duration) (err error) {
|
||||
if deptId <= 0 || uuid == "" {
|
||||
return errors.New("api auth active token key invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthActiveToken, deptId)
|
||||
if err = mcache.Set(ctx, key, uuid, timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = cache.Instance().Set(ctx, key, uuid, timeout); err != nil {
|
||||
_ = mcache.Remove(ctx, key)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetApiAuthActiveToken 获取机构维度的当前有效令牌索引。
|
||||
func GetApiAuthActiveToken(ctx context.Context, deptId int64) (uuid string, err error) {
|
||||
if deptId <= 0 {
|
||||
return "", errors.New("api auth active token key invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthActiveToken, deptId)
|
||||
t, err := mcache.Instance().Get(ctx, key)
|
||||
if err == nil && !t.IsNil() {
|
||||
return t.String(), nil
|
||||
}
|
||||
|
||||
t, err = cache.Instance().Get(ctx, key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !t.IsNil() {
|
||||
_ = mcache.Set(ctx, key, t.String(), apiAuthLocalBackfillTTL)
|
||||
return t.String(), nil
|
||||
}
|
||||
return "", errors.New("api auth active token not found")
|
||||
}
|
||||
|
||||
// DelApiAuthActiveToken 删除机构维度的当前有效令牌索引。
|
||||
func DelApiAuthActiveToken(ctx context.Context, deptId int64) (err error) {
|
||||
if deptId <= 0 {
|
||||
return errors.New("api auth active token key invalid")
|
||||
}
|
||||
key := fmt.Sprintf(consts.KeyApiAuthActiveToken, deptId)
|
||||
if err = mcache.Remove(ctx, key); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = cache.Instance().Remove(ctx, key)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user