Compare commits
No commits in common. "main" and "v0.0.44" have entirely different histories.
|
@ -15,18 +15,13 @@ var (
|
||||||
|
|
||||||
// standard error code ,start:110
|
// standard error code ,start:110
|
||||||
var (
|
var (
|
||||||
ErrEmpty = NewError(110, "Data Is Empty")
|
ErrEmpty = NewError(110, "Data Is Empty")
|
||||||
ErrRequestParse = NewError(111, "Request Parse Fail")
|
ErrRequestParse = NewError(111, "Request Parse Fail")
|
||||||
ErrRequestMust = NewError(112, "Request Params Required")
|
ErrRequestMust = NewError(112, "Request Params Required")
|
||||||
ErrPermission = NewError(113, "Permission Denied")
|
ErrPermission = NewError(113, "Permission Denied")
|
||||||
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
||||||
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
||||||
ErrInternal = NewError(116, "Internal Server Error")
|
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
|
// jwt error code ,start:130
|
||||||
|
|
|
@ -8,29 +8,29 @@ import (
|
||||||
var Response Reply
|
var Response Reply
|
||||||
|
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
Code int32 `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Msg string `json:"msg"`
|
||||||
Result any `json:"result"`
|
Data any `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
reply.Code = 0
|
reply.Code = 200
|
||||||
reply.Result = data
|
reply.Data = data
|
||||||
reply.Message = ""
|
reply.Msg = ""
|
||||||
if data == nil {
|
if data == nil {
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
}
|
}
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||||
reply.Code = 500
|
reply.Code = 500
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
// Status code defaults to 500
|
// Status code defaults to 500
|
||||||
e, ok := status.FromError(err)
|
e, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
reply.Code = int32(e.Code())
|
reply.Code = int(e.Code())
|
||||||
}
|
}
|
||||||
reply.Message = e.Message()
|
reply.Msg = e.Message()
|
||||||
|
|
||||||
// Send error
|
// Send error
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
|
|
32
oplog/new.go
32
oplog/new.go
|
@ -1,14 +1,32 @@
|
||||||
package oplog
|
package oplog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"git.apinb.com/bsm-sdk/core/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(endpoint string, data []*LogItem) {
|
func New(endpoint string, data []*LogItem) error {
|
||||||
jsonBytes, _ := json.Marshal(data)
|
go PostLog(data, endpoint)
|
||||||
|
return nil
|
||||||
go utils.HttpPost(endpoint, nil, jsonBytes)
|
}
|
||||||
|
func PostLog(data []*LogItem, endpoint string) (resp *http.Response, err error) {
|
||||||
|
jsonBytes, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(jsonBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package oplog
|
package oplog
|
||||||
|
|
||||||
|
type LogRequest struct {
|
||||||
|
Data []*LogItem `json:"data"`
|
||||||
|
}
|
||||||
type LogItem struct {
|
type LogItem struct {
|
||||||
OpID uint `json:"op_id"`
|
OpID uint `json:"op_id"`
|
||||||
OpName string `json:"op_name"`
|
OpName string `json:"op_name"`
|
||||||
|
|
24
types/db.go
24
types/db.go
|
@ -21,15 +21,15 @@ type (
|
||||||
// standard ID,Identity definition.
|
// standard ID,Identity definition.
|
||||||
Std_IDIdentity struct {
|
Std_IDIdentity struct {
|
||||||
ID uint `gorm:"primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Created,Updated,Deleted definition.
|
// standard ID,Created,Updated,Deleted definition.
|
||||||
Std_IICUDS struct {
|
Std_IICUDS struct {
|
||||||
ID uint `gorm:"primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
||||||
CreatedAt time.Time `gorm:"" json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"" json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
||||||
Status int8 `gorm:"default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
Status int8 `gorm:"default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
||||||
}
|
}
|
||||||
|
@ -37,27 +37,21 @@ type (
|
||||||
// standard ID,Identity,Created,Updated,Deleted,Status definition.
|
// standard ID,Identity,Created,Updated,Deleted,Status definition.
|
||||||
Std_ICUD struct {
|
Std_ICUD struct {
|
||||||
ID uint `gorm:"primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
CreatedAt time.Time `gorm:"" json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"" json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Created definition.
|
// standard ID,Created definition.
|
||||||
Std_IdCreated struct {
|
Std_IdCreated struct {
|
||||||
ID uint `gorm:"primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
CreatedAt time.Time `gorm:"" json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard PassportID,PassportIdentity definition.
|
// standard PassportID,PassportIdentity definition.
|
||||||
Std_Passport struct {
|
Std_Passport struct {
|
||||||
PassportID uint `gorm:"column:passport_id;Index;" json:"passport_id"`
|
PassportID uint `gorm:"column:passport_id;Index;" json:"passport_id"`
|
||||||
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;" json:"passport_identity"` // 用户唯一标识,24位NanoID,36位为UUID
|
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;default:uuid_generate_v4()" json:"passport_identity"` // 用户唯一标识,24位NanoID,36位为ULID
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
// standard ID definition.
|
||||||
|
@ -67,7 +61,7 @@ type (
|
||||||
|
|
||||||
// standard Identity definition.
|
// standard Identity definition.
|
||||||
Std_Identity struct {
|
Std_Identity struct {
|
||||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为UUID
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;default:uuid_generate_v4()" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard Status definition.
|
// standard Status definition.
|
||||||
|
|
Loading…
Reference in New Issue