Compare commits

..

6 Commits

Author SHA1 Message Date
yanweidong 4d06ad3e8b add err code 2025-04-19 20:14:37 +08:00
yanweidong 52a81a404e fix infra response 2025-04-18 19:11:50 +08:00
yanweidong 6cd06d86bc add std_owner 2025-04-17 17:18:58 +08:00
zhaoxiaorong ca9f7047c6 fix 兼容性调整 2025-04-15 21:49:17 +08:00
zhaoxiaorong 2de73fea00 fix 兼容性调整 2025-04-15 20:50:28 +08:00
zhaoxiaorong 4b73f086b1 dev oplog 2025-04-11 18:14:07 +08:00
5 changed files with 42 additions and 52 deletions

View File

@ -15,13 +15,18 @@ var (
// standard error code ,start:110
var (
ErrEmpty = NewError(110, "Data Is Empty")
ErrRequestParse = NewError(111, "Request Parse Fail")
ErrRequestMust = NewError(112, "Request Params Required")
ErrPermission = NewError(113, "Permission Denied")
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
ErrInternal = NewError(116, "Internal Server Error")
ErrEmpty = NewError(110, "Data Is Empty")
ErrRequestParse = NewError(111, "Request Parse Fail")
ErrRequestMust = NewError(112, "Request Params Required")
ErrPermission = NewError(113, "Permission Denied")
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
ErrInternal = NewError(116, "Internal Server Error")
ErrPassword = NewError(117, "Password Incorrect")
ErrAccountNotFound = NewError(118, "Account Not Found")
ErrAccountDisabled = NewError(119, "Account Disabled")
ErrDisabled = NewError(120, "Status Disabled")
ErrRecordNotFound = NewError(121, "Record Not Found")
)
// jwt error code ,start:130

View File

@ -8,29 +8,29 @@ import (
var Response Reply
type Reply struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data any `json:"data"`
Code int32 `json:"code"`
Message string `json:"message"`
Result any `json:"result"`
}
func (reply *Reply) Success(ctx *gin.Context, data any) {
reply.Code = 200
reply.Data = data
reply.Msg = ""
reply.Code = 0
reply.Result = data
reply.Message = ""
if data == nil {
reply.Data = ""
reply.Result = ""
}
ctx.JSON(200, reply)
}
func (reply *Reply) Error(ctx *gin.Context, err error) {
reply.Code = 500
reply.Data = ""
reply.Result = ""
// Status code defaults to 500
e, ok := status.FromError(err)
if ok {
reply.Code = int(e.Code())
reply.Code = int32(e.Code())
}
reply.Msg = e.Message()
reply.Message = e.Message()
// Send error
ctx.JSON(200, reply)

View File

@ -1,32 +1,14 @@
package oplog
import (
"bytes"
"encoding/json"
"net/http"
"git.apinb.com/bsm-sdk/core/utils"
)
func New(endpoint string, data []*LogItem) error {
go PostLog(data, endpoint)
return nil
}
func PostLog(data []*LogItem, endpoint string) (resp *http.Response, err error) {
jsonBytes, err := json.Marshal(data)
if err != nil {
return nil, err
}
func New(endpoint string, data []*LogItem) {
jsonBytes, _ := json.Marshal(data)
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(jsonBytes))
if err != nil {
return nil, err
}
go utils.HttpPost(endpoint, nil, jsonBytes)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err = client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return
}

View File

@ -1,8 +1,5 @@
package oplog
type LogRequest struct {
Data []*LogItem `json:"data"`
}
type LogItem struct {
OpID uint `json:"op_id"`
OpName string `json:"op_name"`

View File

@ -21,15 +21,15 @@ type (
// standard ID,Identity definition.
Std_IDIdentity struct {
ID uint `gorm:"primarykey;" json:"id"`
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识24位NanoID,36位为ULID
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为ULID
}
// standard ID,Created,Updated,Deleted definition.
Std_IICUDS struct {
ID uint `gorm:"primarykey;" json:"id"`
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识24位NanoID,36位为ULID
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为ULID
CreatedAt time.Time `gorm:"" json:"created_at"`
UpdatedAt time.Time `gorm:"" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
Status int8 `gorm:"default:0;index;" json:"status"` // 状态默认为0-1禁止1为正常
}
@ -37,21 +37,27 @@ type (
// standard ID,Identity,Created,Updated,Deleted,Status definition.
Std_ICUD struct {
ID uint `gorm:"primarykey;" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `gorm:"" json:"created_at"`
UpdatedAt time.Time `gorm:"" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
}
// standard ID,Created definition.
Std_IdCreated struct {
ID uint `gorm:"primarykey;" json:"id"`
CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `gorm:"" json:"created_at"`
}
// standard PassportID,PassportIdentity definition.
Std_Passport struct {
PassportID uint `gorm:"column:passport_id;Index;" json:"passport_id"`
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;default:uuid_generate_v4()" json:"passport_identity"` // 用户唯一标识24位NanoID,36位为ULID
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;" json:"passport_identity"` // 用户唯一标识24位NanoID,36位为UUID
}
// standard OwnerID,OwnerIdentity definition.
Std_Owner struct {
OwnerID uint `gorm:"column:owner_id;Index;" json:"owner_id"`
OwnerIdentity string `gorm:"column:owner_identity;type:varchar(36);Index;" json:"owner_identity"` // 用户唯一标识24位NanoID,36位为UUID
}
// standard ID definition.
@ -61,7 +67,7 @@ type (
// standard Identity definition.
Std_Identity struct {
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识24位NanoID,36位为ULID
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为UUID
}
// standard Status definition.