Ver Fonte

DateTime

- implement easyjson
Alexey Kim há 1 ano atrás
pai
commit
3ec3746ff3
1 ficheiros alterados com 15 adições e 0 exclusões
  1. 15 0
      model/datetime.go

+ 15 - 0
model/datetime.go

@@ -3,6 +3,8 @@ package model
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/mailru/easyjson/jlexer"
+	"github.com/mailru/easyjson/jwriter"
 	"io"
 	"log"
 	"regexp"
@@ -91,3 +93,16 @@ func (d *DateTime) Scan(src any) error {
 
 	return fmt.Errorf("cannot scan %T into DateTime", src)
 }
+
+func (d *DateTime) MarshalEasyJSON(w *jwriter.Writer) {
+	w.RawString(fmt.Sprintf("%d", d))
+}
+
+func (d *DateTime) UnmarshalEasyJSON(l *jlexer.Lexer) {
+	if l.IsNull() {
+		l.Skip()
+		*d = DateTime(0)
+	} else {
+		*d = DateTime(l.Int64())
+	}
+}