mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 16:01:17 +00:00
feat(backend): impl share expiry update
This commit is contained in:
28
apps/backend/internal/nullable/time.go
Normal file
28
apps/backend/internal/nullable/time.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package nullable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Time tracks whether a JSON field was set and stores an optional time value.
|
||||
type Time struct {
|
||||
Time *time.Time
|
||||
Set bool
|
||||
}
|
||||
|
||||
func (nt *Time) UnmarshalJSON(b []byte) error {
|
||||
nt.Set = true
|
||||
if bytes.Equal(bytes.TrimSpace(b), []byte("null")) {
|
||||
nt.Time = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var t time.Time
|
||||
if err := json.Unmarshal(b, &t); err != nil {
|
||||
return err
|
||||
}
|
||||
nt.Time = &t
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user