提交 682d28fb authored 作者: mooncake's avatar mooncake

update

上级 b79900e0
package xgin package xgin
import ( import (
"context"
"fmt" "fmt"
"time" "time"
...@@ -16,7 +15,6 @@ import ( ...@@ -16,7 +15,6 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/gin/prof" "gitlab.wanzhuangkj.com/tush/xpkg/gin/prof"
"gitlab.wanzhuangkj.com/tush/xpkg/global" "gitlab.wanzhuangkj.com/tush/xpkg/global"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/goredis"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/ips"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/jwt"
...@@ -26,7 +24,7 @@ import ( ...@@ -26,7 +24,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/xutils/weblogutils" "gitlab.wanzhuangkj.com/tush/xpkg/xutils/weblogutils"
) )
func New() *gin.Engine { func New(h func(g *gin.Engine)) *gin.Engine {
var app config.App var app config.App
var auth config.Auth var auth config.Auth
var httpCfg config.HTTP var httpCfg config.HTTP
...@@ -121,17 +119,21 @@ func New() *gin.Engine { ...@@ -121,17 +119,21 @@ func New() *gin.Engine {
weblogutils.Init() weblogutils.Init()
if h != nil {
h(r)
}
if config.IsNotProd() { if config.IsNotProd() {
contextPath := app.ContextPath contextPath := app.ContextPath
r.GET(contextPath+"/config", gin.WrapF(errcode.ShowConfig([]byte(config.Show())))) r.GET(contextPath+"/config", gin.WrapF(errcode.ShowConfig([]byte(config.Show()))))
r.GET(contextPath+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) r.GET(contextPath+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
eventbus.Eb.Subscribe(eventbus.TopicPrintSwagger, func(ctx context.Context) {
fmt.Println(text.Blue(fmt.Sprintf("swagger: http://localhost:%d"+contextPath+"/swagger/index.html", httpCfg.Port))) fmt.Println(text.Blue(fmt.Sprintf("swagger: http://localhost:%d"+contextPath+"/swagger/index.html", httpCfg.Port)))
ip := ips.GetLocalHost() ip := ips.GetLocalHost()
if ip != "" { if ip != "" {
fmt.Println(text.Blue(fmt.Sprintf("swagger: https://%s:%d"+contextPath+"/swagger/index.html", ip, httpCfg.Port))) fmt.Println(text.Blue(fmt.Sprintf("swagger: https://%s:%d"+contextPath+"/swagger/index.html", ip, httpCfg.Port)))
} }
})
} }
r.GET("/health", handlerfunc.CheckHealth) r.GET("/health", handlerfunc.CheckHealth)
......
...@@ -24,6 +24,7 @@ const ( ...@@ -24,6 +24,7 @@ const (
Layout_YYYYMMDD = "2006-01-02" Layout_YYYYMMDD = "2006-01-02"
Layout_YYYYMMDD2 = "2006/01/02" Layout_YYYYMMDD2 = "2006/01/02"
Layout_YYYYMMDD3 = "20060102" Layout_YYYYMMDD3 = "20060102"
Layout_YYYYMMDD4 = "2006年01月02日"
Layout_YYYYMMDDHHmmSS = "2006-01-02 15:04:05" Layout_YYYYMMDDHHmmSS = "2006-01-02 15:04:05"
) )
...@@ -44,7 +45,7 @@ const ( ...@@ -44,7 +45,7 @@ const (
// MarshalJSON 自定义JSON序列化 // MarshalJSON 自定义JSON序列化
func (dt DateTime) MarshalJSON() ([]byte, error) { func (dt DateTime) MarshalJSON() ([]byte, error) {
t := time.Time(dt) t := dt.Time()
if t.IsZero() { if t.IsZero() {
return []byte("null"), nil return []byte("null"), nil
} }
...@@ -72,7 +73,7 @@ func (dt *DateTime) UnmarshalJSON(data []byte) error { ...@@ -72,7 +73,7 @@ func (dt *DateTime) UnmarshalJSON(data []byte) error {
// MarshalYAML 自定义YAML序列化 // MarshalYAML 自定义YAML序列化
func (dt DateTime) MarshalYAML() (any, error) { func (dt DateTime) MarshalYAML() (any, error) {
t := time.Time(dt) t := dt.Time()
if t.IsZero() { if t.IsZero() {
return nil, nil return nil, nil
} }
...@@ -96,7 +97,7 @@ func (dt *DateTime) UnmarshalYAML(value *yaml.Node) error { ...@@ -96,7 +97,7 @@ func (dt *DateTime) UnmarshalYAML(value *yaml.Node) error {
// String 返回日期时间的字符串表示 // String 返回日期时间的字符串表示
func (dt DateTime) String() string { func (dt DateTime) String() string {
t := time.Time(dt) t := dt.Time()
if t.IsZero() { if t.IsZero() {
return "" return ""
} }
...@@ -123,7 +124,7 @@ func (dt *DateTime) parseString(s string) error { ...@@ -123,7 +124,7 @@ func (dt *DateTime) parseString(s string) error {
var firstErr error var firstErr error
for _, format := range formats { for _, format := range formats {
parsed, err := time.Parse(format, s) parsed, err := time.ParseInLocation(format, s, LocBeiJing)
if err == nil { if err == nil {
*dt = DateTime(parsed) *dt = DateTime(parsed)
return nil return nil
...@@ -143,7 +144,7 @@ func (dt DateTime) Time() time.Time { ...@@ -143,7 +144,7 @@ func (dt DateTime) Time() time.Time {
// IsZero 检查是否为零值 // IsZero 检查是否为零值
func (dt DateTime) IsZero() bool { func (dt DateTime) IsZero() bool {
return time.Time(dt).IsZero() return dt.Time().IsZero()
} }
// IsNotZero 检查是否非零值 // IsNotZero 检查是否非零值
...@@ -153,12 +154,12 @@ func (dt DateTime) IsNotZero() bool { ...@@ -153,12 +154,12 @@ func (dt DateTime) IsNotZero() bool {
// Format 使用自定义格式格式化日期时间 // Format 使用自定义格式格式化日期时间
func (dt DateTime) Format(layout string) string { func (dt DateTime) Format(layout string) string {
return time.Time(dt).Format(layout) return dt.Time().Format(layout)
} }
// Value 实现 driver.Valuer 接口,用于数据库存储 // Value 实现 driver.Valuer 接口,用于数据库存储
func (dt DateTime) Value() (driver.Value, error) { func (dt DateTime) Value() (driver.Value, error) {
t := time.Time(dt) t := dt.Time()
if t.IsZero() { if t.IsZero() {
return nil, nil return nil, nil
} }
...@@ -195,32 +196,32 @@ func (dt *DateTime) Scan(value any) error { ...@@ -195,32 +196,32 @@ func (dt *DateTime) Scan(value any) error {
// After 检查当前时间是否在另一个时间之后 // After 检查当前时间是否在另一个时间之后
func (dt DateTime) After(other DateTime) bool { func (dt DateTime) After(other DateTime) bool {
return time.Time(dt).After(time.Time(other)) return dt.Time().After(other.Time())
} }
// Before 检查当前时间是否在另一个时间之前 // Before 检查当前时间是否在另一个时间之前
func (dt DateTime) Before(other DateTime) bool { func (dt DateTime) Before(other DateTime) bool {
return time.Time(dt).Before(time.Time(other)) return dt.Time().Before(other.Time())
} }
// Equal 检查两个时间是否相等 // Equal 检查两个时间是否相等
func (dt DateTime) Equal(other DateTime) bool { func (dt DateTime) Equal(other DateTime) bool {
return time.Time(dt).Equal(time.Time(other)) return dt.Time().Equal(other.Time())
} }
// Add 添加时间间隔 // Add 添加时间间隔
func (dt DateTime) Add(duration time.Duration) DateTime { func (dt DateTime) Add(duration time.Duration) DateTime {
return DateTime(time.Time(dt).Add(duration)) return DateTime(dt.Time().Add(duration))
} }
// Unix 返回Unix时间戳 // Unix 返回Unix时间戳
func (dt DateTime) Unix() int64 { func (dt DateTime) Unix() int64 {
return time.Time(dt).Unix() return dt.Time().Unix()
} }
// UnixNano 返回纳秒级Unix时间戳 // UnixNano 返回纳秒级Unix时间戳
func (dt DateTime) UnixNano() int64 { func (dt DateTime) UnixNano() int64 {
return time.Time(dt).UnixNano() return dt.Time().UnixNano()
} }
// 构造函数 // 构造函数
...@@ -373,7 +374,7 @@ func (t0 DateTime) MonthEnd() DateTime { ...@@ -373,7 +374,7 @@ func (t0 DateTime) MonthEnd() DateTime {
// AddDate 添加年、月、日,正确处理月份边界溢出 // AddDate 添加年、月、日,正确处理月份边界溢出
func (dt DateTime) AddDate(years, months, days int) DateTime { func (dt DateTime) AddDate(years, months, days int) DateTime {
t := time.Time(dt) t := dt.Time()
y, m, d := t.Date() y, m, d := t.Date()
h, min, s := t.Clock() h, min, s := t.Clock()
nsec := t.Nanosecond() nsec := t.Nanosecond()
...@@ -530,27 +531,27 @@ func DaysBetween(t0, t1 DateTime) int { ...@@ -530,27 +531,27 @@ func DaysBetween(t0, t1 DateTime) int {
// 时间组件获取方法 // 时间组件获取方法
func (dt DateTime) Hour() int { func (dt DateTime) Hour() int {
return time.Time(dt).Hour() return dt.Time().Hour()
} }
func (dt DateTime) Minute() int { func (dt DateTime) Minute() int {
return time.Time(dt).Minute() return dt.Time().Minute()
} }
func (dt DateTime) Second() int { func (dt DateTime) Second() int {
return time.Time(dt).Second() return dt.Time().Second()
} }
func (dt DateTime) Year() int { func (dt DateTime) Year() int {
return time.Time(dt).Year() return dt.Time().Year()
} }
// func (dt DateTime) Month() time.Month { // func (dt DateTime) Month() time.Month {
// return time.Time(dt).Month() // return dt.Time().Month()
// } // }
func (dt DateTime) Day() int { func (dt DateTime) Day() int {
return time.Time(dt).Day() return dt.Time().Day()
} }
// 月份常量(Go语言time包内置,直接使用) // 月份常量(Go语言time包内置,直接使用)
...@@ -561,7 +562,7 @@ func (dt DateTime) Day() int { ...@@ -561,7 +562,7 @@ func (dt DateTime) Day() int {
// MarshalCSV 实现CSV序列化方法 // MarshalCSV 实现CSV序列化方法
func (d DateTime) MarshalCSV() (string, error) { func (d DateTime) MarshalCSV() (string, error) {
t := time.Time(d) t := d.Time()
if t.IsZero() { if t.IsZero() {
return "", nil return "", nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论