enhance(time):调整日期时间在输出位JSON时的默认格式。
This commit is contained in:
parent
409f9af1c4
commit
e79d34a136
1
go.mod
1
go.mod
|
@ -29,6 +29,7 @@ require (
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/liamylian/jsontime/v2 v2.0.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -313,6 +313,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
|
||||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||||
|
@ -338,6 +339,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||||
|
github.com/liamylian/jsontime/v2 v2.0.0 h1:3if2kDW/boymUdO+4Qj/m4uaXMBSF6np9KEgg90cwH0=
|
||||||
|
github.com/liamylian/jsontime/v2 v2.0.0/go.mod h1:UHp1oAPqCBfspokvGmaGe0IAl2IgOpgOgDaKPcvcGGY=
|
||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
|
|
6
main.go
6
main.go
|
@ -16,6 +16,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
jsontime "github.com/liamylian/jsontime/v2/v2"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,6 +67,11 @@ func init() {
|
||||||
log.Fatalf("Singularity account intialize failed: %v", err)
|
log.Fatalf("Singularity account intialize failed: %v", err)
|
||||||
}
|
}
|
||||||
log.Println("Singularity account intialized.")
|
log.Println("Singularity account intialized.")
|
||||||
|
|
||||||
|
timeZoneShanghai, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
|
jsontime.AddTimeFormatAlias("simple_datetime", "2006-01-02 15:04:05")
|
||||||
|
jsontime.AddTimeFormatAlias("simple_date", "2006-01-02")
|
||||||
|
jsontime.AddLocaleAlias("shanghai", timeZoneShanghai)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeRegions() error {
|
func initializeRegions() error {
|
||||||
|
|
|
@ -7,12 +7,12 @@ type Report struct {
|
||||||
Deleted `xorm:"extends"`
|
Deleted `xorm:"extends"`
|
||||||
Id string `xorm:"varchar(120) pk not null" json:"id"`
|
Id string `xorm:"varchar(120) pk not null" json:"id"`
|
||||||
ParkId string `xorm:"varchar(120) not null" json:"parkId"`
|
ParkId string `xorm:"varchar(120) not null" json:"parkId"`
|
||||||
Period time.Time `xorm:"date not null" json:"period"`
|
Period time.Time `xorm:"date not null" json:"period" time_format:"simple_date" time_location:"shanghai"`
|
||||||
Published bool `xorm:"bool not null default false" json:"published"`
|
Published bool `xorm:"bool not null default false" json:"published"`
|
||||||
PublishedAt *time.Time `xorm:"timestampz" json:"publishedAt"`
|
PublishedAt *time.Time `xorm:"timestampz" json:"publishedAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
Withdraw int8 `xorm:"smallint not null default 0" json:"withdraw"`
|
Withdraw int8 `xorm:"smallint not null default 0" json:"withdraw"`
|
||||||
LastWithdrawAppliedAt *time.Time `xorm:"timestampz" json:"lastWithdrawAppliedAt"`
|
LastWithdrawAppliedAt *time.Time `xorm:"timestampz" json:"lastWithdrawAppliedAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
LastWithdrawAuditAt *time.Time `xorm:"timestampz" json:"lastWithdrawAuditAt"`
|
LastWithdrawAuditAt *time.Time `xorm:"timestampz" json:"lastWithdrawAuditAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Report) TableName() string {
|
func (Report) TableName() string {
|
||||||
|
|
|
@ -7,5 +7,5 @@ type Session struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type int8 `json:"type"`
|
Type int8 `json:"type"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
ExpiresAt time.Time `json:"expiresAt"`
|
ExpiresAt time.Time `json:"expiresAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package model
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Created struct {
|
type Created struct {
|
||||||
CreatedAt time.Time `xorm:"timestampz not null created" json:"createdAt"`
|
CreatedAt time.Time `xorm:"timestampz not null created" json:"createdAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatedWithUser struct {
|
type CreatedWithUser struct {
|
||||||
|
@ -12,7 +12,7 @@ type CreatedWithUser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deleted struct {
|
type Deleted struct {
|
||||||
DeletedAt *time.Time `xorm:"timestampz deleted" json:"deletedAt"`
|
DeletedAt *time.Time `xorm:"timestampz deleted" json:"deletedAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeletedWithUser struct {
|
type DeletedWithUser struct {
|
||||||
|
@ -22,7 +22,7 @@ type DeletedWithUser struct {
|
||||||
|
|
||||||
type CreatedAndModified struct {
|
type CreatedAndModified struct {
|
||||||
Created `xorm:"extends"`
|
Created `xorm:"extends"`
|
||||||
LastModifiedAt *time.Time `xorm:"timestampz updated" json:"lastModifiedAt"`
|
LastModifiedAt *time.Time `xorm:"timestampz updated" json:"lastModifiedAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatedAndModifiedWithUser struct {
|
type CreatedAndModifiedWithUser struct {
|
||||||
|
|
|
@ -14,9 +14,9 @@ type UserCharge struct {
|
||||||
Discount decimal.Decimal `xorm:"numeric(5,4) not null" json:"discount"`
|
Discount decimal.Decimal `xorm:"numeric(5,4) not null" json:"discount"`
|
||||||
Amount decimal.Decimal `xorm:"numeric(12,2) not null" json:"amount"`
|
Amount decimal.Decimal `xorm:"numeric(12,2) not null" json:"amount"`
|
||||||
Settled bool `xorm:"bool not null default false" json:"settled"`
|
Settled bool `xorm:"bool not null default false" json:"settled"`
|
||||||
SettledAt *time.Time `xorm:"timestampz" json:"settledAt"`
|
SettledAt *time.Time `xorm:"timestampz" json:"settledAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
Refunded bool `xorm:"bool not null default false" json:"refunded"`
|
Refunded bool `xorm:"bool not null default false" json:"refunded"`
|
||||||
RefundedAt *time.Time `xorm:"timestampz" json:"refundedAt"`
|
RefundedAt *time.Time `xorm:"timestampz" json:"refundedAt" time_format:"simple_datetime" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserCharge) TableName() string {
|
func (UserCharge) TableName() string {
|
||||||
|
|
|
@ -17,7 +17,7 @@ type UserDetail struct {
|
||||||
Contact *string `xorm:"varchar(100)" json:"contact"`
|
Contact *string `xorm:"varchar(100)" json:"contact"`
|
||||||
Phone *string `xorm:"varchar(50)" json:"phone"`
|
Phone *string `xorm:"varchar(50)" json:"phone"`
|
||||||
UnitServiceFee decimal.Decimal `xorm:"numeric(8,2) not null" json:"unitServiceFee"`
|
UnitServiceFee decimal.Decimal `xorm:"numeric(8,2) not null" json:"unitServiceFee"`
|
||||||
ServiceExpiration time.Time `xorm:"date not null" json:"serviceExpiration"`
|
ServiceExpiration time.Time `xorm:"date not null" json:"serviceExpiration" time_format:"simple_date" time_location:"shanghai"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserDetail) TableName() string {
|
func (UserDetail) TableName() string {
|
||||||
|
@ -34,3 +34,12 @@ type JoinedUserDetail struct {
|
||||||
func (JoinedUserDetail) TableName() string {
|
func (JoinedUserDetail) TableName() string {
|
||||||
return "user"
|
return "user"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FullJoinedUserDetail struct {
|
||||||
|
User `xorm:"extends"`
|
||||||
|
UserDetail `xorm:"extends"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (FullJoinedUserDetail) TableName() string {
|
||||||
|
return "user"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user