Merge branch 'master' of https://git.apinb.com/bsm-sdk/engine
This commit is contained in:
commit
31c602dcc5
|
@ -31,7 +31,8 @@ func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) {
|
|||
// PreferSimpleProtocol: true, disables implicit prepared statement usage
|
||||
|
||||
}), &gorm.Config{
|
||||
Logger: newLogger,
|
||||
Logger: newLogger,
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
NamingStrategy: schema.NamingStrategy{
|
||||
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
|
||||
}})
|
||||
|
|
|
@ -26,7 +26,7 @@ func New() {
|
|||
JwtSecretLen = len(env.MeshEnv.JwtSecretKey)
|
||||
}
|
||||
|
||||
func GenerateTokenAes(id uint, identity, client, role string, extend map[string]string) (string, error) {
|
||||
func GenerateTokenAes(id uint, identity, client, role string, owner any, extend map[string]string) (string, error) {
|
||||
if (JwtSecretLen == 16 || JwtSecretLen == 24 || JwtSecretLen == 32) == false {
|
||||
return "", exception.ErrAuthSecret
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func GenerateTokenAes(id uint, identity, client, role string, extend map[string]
|
|||
ID: id,
|
||||
Identity: identity,
|
||||
Extend: extend,
|
||||
Client: client,
|
||||
Owner: owner,
|
||||
Role: role,
|
||||
ExpiresAt: expireTime.Unix(),
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@ var (
|
|||
ErrJSONUnmarshal = Errorf(18, "Unmarshal JSON")
|
||||
ErrPasswd = Errorf(19, "Password Error")
|
||||
|
||||
ErrSmsCode = Errorf(20, "SMS Code Invalid")
|
||||
ErrSmsCode = Errorf(20, "SMS Code Invalid")
|
||||
ErrIdArgument = Errorf(30, "ID Invalid Argument")
|
||||
ErrIdentityArgument = Errorf(31, "Identity Invalid Argument")
|
||||
|
||||
// coustom error status
|
||||
)
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"git.apinb.com/bsm-sdk/engine/encipher"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/types"
|
||||
"git.apinb.com/bsm-sdk/engine/utils"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
|
@ -38,11 +37,6 @@ func ParseMetaCtx(ctx context.Context, opts *ParseOptions) (*types.JwtClaims, er
|
|||
if !strings.Contains(claims.Role, opts.RoleValue) {
|
||||
return nil, exception.ErrPermissionDenied
|
||||
}
|
||||
if opts.MustPrivateAllow {
|
||||
if utils.IsPublicIP(claims.Client) {
|
||||
return nil, exception.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package types
|
||||
|
||||
type Message struct {
|
||||
TimeSequence int64 //消息创建的时间戳
|
||||
SessionIdent string // 会话唯一标识
|
||||
SenderId int64
|
||||
SenderIdentity string
|
||||
TargetId int64
|
||||
TargetIdentity string
|
||||
GroupId int64 //群组唯一ID,在群聊消息的时候使用到。不使用时则为空
|
||||
GroupIdentity string //群组唯一码,在群聊消息的时候使用到。不使用时则为空
|
||||
MsgType int32 //0异常提示,1单聊,2群聊,3系统
|
||||
BodyType int32 //正文类型:0文本,1图片,2,视频,3.....
|
||||
Body string
|
||||
Status int32 //消息状态:0待续,1存储成功,2送达确认,3已读确认,-1撤回
|
||||
}
|
||||
|
||||
type ChatMessage struct {
|
||||
TimeSequence int64 //消息创建的时间戳
|
||||
SessionIdent string // 会话唯一标识
|
||||
SenderId int64
|
||||
SenderIdentity string
|
||||
TargetId int64
|
||||
TargetIdentity string
|
||||
BodyType int32 //正文类型:0文本,1图片,2,视频,3.....
|
||||
Body string
|
||||
Status int32 //消息状态:0待续,1存储成功,2送达确认,3已读确认,-1撤回
|
||||
}
|
||||
|
||||
type GroupMessage struct {
|
||||
TimeSequence int64 //消息创建的时间戳
|
||||
GroupId int64 //群组唯一ID,在群聊消息的时候使用到。不使用时则为空
|
||||
GroupIdentity string //群组唯一标识,在群聊消息的时候使用到。不使用时则为空
|
||||
SenderId int64
|
||||
SenderIdentity string
|
||||
BodyType int32 //正文类型:0文本,1图片,2,视频,3.....
|
||||
Body string
|
||||
Status int32 //消息状态:0待续,1存储成功,2送达确认,3已读确认,-1撤回
|
||||
}
|
||||
|
||||
type SystemMessage struct {
|
||||
TimeSequence int64 //消息创建的时间戳
|
||||
TargetId int64
|
||||
TargetIdentity string
|
||||
BodyType int32 //正文类型:0文本,1图片,2,视频,3.....
|
||||
Body string
|
||||
Status int32 //消息状态:0待续,1存储成功,2送达确认,3已读确认,-1撤回
|
||||
}
|
||||
|
||||
type EventMessage struct {
|
||||
TimeSequence int64 //消息创建的时间戳
|
||||
TargetId int64
|
||||
TargetIdentity string
|
||||
EventType int32 //事件类型:0 正在输入,已送达...
|
||||
Status int32 //消息状态:0待续,1存储成功,2送达确认,3已读确认,-1撤回
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaevor/go-nanoid"
|
||||
ulid "github.com/oklog/ulid/v2"
|
||||
)
|
||||
|
||||
func NanoID() string {
|
||||
|
@ -13,7 +14,7 @@ func NanoID() string {
|
|||
}
|
||||
|
||||
func NanoIDInt() (id int64, err error) {
|
||||
decenaryID, err := nanoid.CustomASCII("0123456789", 20)
|
||||
decenaryID, err := nanoid.CustomASCII("0123456789", 18)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -24,3 +25,7 @@ func NanoIDInt() (id int64, err error) {
|
|||
func UUID() string {
|
||||
return uuid.NewString()
|
||||
}
|
||||
|
||||
func ULID() string {
|
||||
return ulid.Make().String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue