提交 c0316c80 authored 作者: mooncake9527's avatar mooncake9527

update

上级 1d37e613
......@@ -2,12 +2,13 @@ package middleware
import (
"bytes"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/gin/xctx"
"gitlab.wanzhuangkj.com/tush/xpkg/ips"
"io"
"net/http"
"time"
ctxUtil "gitlab.wanzhuangkj.com/tush/xpkg/gin/xctx"
"gitlab.wanzhuangkj.com/tush/xpkg/ips"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
......@@ -203,6 +204,7 @@ func Logging(opts ...Option) gin.HandlerFunc {
zap.Int("code", c.Writer.Status()),
zap.String("method", c.Request.Method),
zap.String("url", c.Request.URL.Path),
zap.String("client_ip", ip),
zap.String("cost", time.Since(start).String()),
zap.Int("size", newWriter.body.Len()),
zap.Any("header", c.Writer.Header()),
......
......@@ -2,6 +2,7 @@ package xctx
import (
"context"
xsf "gitlab.wanzhuangkj.com/tush/xpkg/utils/xsnowflake"
"github.com/gin-gonic/gin"
......@@ -148,6 +149,7 @@ func GetCtxTid(ctx context.Context) string {
return tid
}
// GetIP get ip from context.Context, the client ip is set in gin.Context
func GetIP(ctx context.Context) string {
ip := ""
ipVal := ctx.Value(KeyIP)
......
......@@ -3,9 +3,10 @@ package query
import (
"fmt"
"strings"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xtime"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
"strings"
)
const (
......@@ -71,8 +72,7 @@ type Pagination struct {
PageIndex int `json:"pageIndex" form:"pageIndex" binding:"" validate:"required" example:"1"` // 1-based
PageSize int `json:"pageSize" form:"pageSize" binding:"" validate:"required" example:"10"` // 1-based
Sort string `json:"sort,omitempty" form:"sort" binding:"" validate:"required" example:"-id" query:"type:order"` //排序字段,负号表示降序,多个字段排序中间用,(英文逗号)分隔
CreatedAtPeriod
Unscope bool `json:"-" form:"-" query:"-"`
Unscope bool `json:"-" form:"-" query:"-"`
}
func (x Pagination) Unscoped() bool {
......@@ -80,8 +80,8 @@ func (x Pagination) Unscoped() bool {
}
type CreatedAtPeriod struct {
CreatedAtBegin xtime.DateTime `json:"createdAtBegin" form:"createdAtBegin" gorm:"column:created_at;type:datetime;comment:创建时间" query:"type:gte;column:created_at" example:"2025-01-01 12:20:26"` //开始日期 >= example:2021-01-01 00:00:00
CreatedAtEnd xtime.DateTime `json:"createdAtEnd" form:"createdAtEnd" gorm:"column:created_at;type:datetime;comment:创建时间" query:"type:lt;column:created_at" example:"2025-02-01 12:20:26"` //结束日期 < example:2021-02-01 00:00:00
CreatedAtBegin xtime.DateTime `json:"createdAtBegin" form:"createdAtBegin" gorm:"column:created_at;type:datetime;comment:创建时间" query:"type:gte;column:created_at" example:"2025-01-01 12:20:26"` //开始日期起始 (>=)
CreatedAtEnd xtime.DateTime `json:"createdAtEnd" form:"createdAtEnd" gorm:"column:created_at;type:datetime;comment:创建时间" query:"type:lt;column:created_at" example:"2025-02-01 12:20:26"` //结束日期截止 (<)
}
func (x Pagination) GetOffset() int {
......
......@@ -18,3 +18,8 @@ func Init(n int64) (err error) {
func Generate() snowflake.ID {
return node.Generate()
}
func GenerateID() uint64 {
sid := Generate()
return uint64(sid.Int64())
}
......@@ -21,12 +21,19 @@ type DateTime time.Time
// 自定义json序列化
func (x DateTime) MarshalJSON() ([]byte, error) {
if x.IsZero() {
return []byte(`""`), nil
}
var jsonTimeStr = fmt.Sprintf(`"%s"`, time.Time(x).Format("2006-01-02 15:04:05"))
return []byte(jsonTimeStr), nil
}
// 自定义json反序列化
func (x *DateTime) UnmarshalJSON(data []byte) error {
if len(data) == 0 || string(data) == `""` {
*x = DateTime{}
return nil
}
t, err := time.Parse(`"2006-01-02 15:04:05"`, string(data))
if err != nil {
return err
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论