mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: json marshalling of custom time (resolve #117)
This commit is contained in:
parent
bb1d6c048d
commit
9e5847b66d
@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
@ -31,6 +32,10 @@ type Interval struct {
|
||||
|
||||
type CustomTime time.Time
|
||||
|
||||
func (j *CustomTime) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(j.String())
|
||||
}
|
||||
|
||||
func (j *CustomTime) UnmarshalJSON(b []byte) error {
|
||||
s := strings.Replace(strings.Trim(string(b), "\""), ".", "", 1)
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
|
@ -34,7 +34,7 @@ type CredentialsReset struct {
|
||||
|
||||
type TimeByUser struct {
|
||||
User string
|
||||
Time CustomTime `swaggertype:"string" format:"date" example:"2006-01-02 15:04:05.000"`
|
||||
Time CustomTime
|
||||
}
|
||||
|
||||
func (c *CredentialsReset) IsValid() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user