ifms_go/pkg/util/schema.go
2025-06-10 17:50:46 +08:00

68 lines
1.2 KiB
Go

package util
import "ifms/pkg/errors"
const (
ReqBodyKey = "req-body"
ResBodyKey = "res-body"
TreePathDelimiter = "."
)
const (
ResSuccessCode = 0
ResFailedCode = 1
)
type ResponseResult struct {
Success bool `json:"success"`
Code int32 `json:"code"`
Data interface{} `json:"data,omitempty"`
Total int64 `json:"total,omitempty"`
Error *errors.Error `json:"error,omitempty"`
}
type PaginationResult struct {
Total int64 `json:"total"`
Current int `json:"current"`
PageSize int `json:"pageSize"`
}
type PaginationParam struct {
Pagination bool `form:"-"`
OnlyCount bool `form:"-"`
Current int `form:"current"`
PageSize int `form:"pageSize" binding:"max=1000"`
}
type QueryOptions struct {
SelectFields []string
OmitFields []string
OrderFields OrderByParams
}
type Direction string
const (
ASC Direction = "ASC"
DESC Direction = "DESC"
)
type OrderByParam struct {
Field string
Direction Direction
}
type OrderByParams []OrderByParam
func (a OrderByParams) ToSQL() string {
if len(a) == 0 {
return ""
}
var sql string
for _, v := range a {
sql += v.Field + " " + string(v.Direction) + ","
}
return sql[:len(sql)-1]
}