diff --git a/database/sql/postgresql.go b/database/sql/postgresql.go index 1480f4e..e0e6747 100644 --- a/database/sql/postgresql.go +++ b/database/sql/postgresql.go @@ -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` }}) diff --git a/encipher/aes.go b/encipher/aes.go index 9a54182..9a2db64 100644 --- a/encipher/aes.go +++ b/encipher/aes.go @@ -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(), } diff --git a/exception/errors.go b/exception/errors.go index d264a41..85f17de 100644 --- a/exception/errors.go +++ b/exception/errors.go @@ -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 ) diff --git a/go.mod b/go.mod index 4c11a0c..baa2731 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module git.apinb.com/bsm-sdk/engine -go 1.22 \ No newline at end of file +go 1.22 diff --git a/service/context.go b/service/context.go index 6a53e4a..3d52993 100644 --- a/service/context.go +++ b/service/context.go @@ -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 diff --git a/types/mcs.go b/types/mcs.go new file mode 100644 index 0000000..e35ed9d --- /dev/null +++ b/types/mcs.go @@ -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撤回 +} diff --git a/utils/identity.go b/utils/identity.go index d342eb8..f0e70ff 100644 --- a/utils/identity.go +++ b/utils/identity.go @@ -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() +}