move api package to sub folder

This commit is contained in:
Samuel Lorch 2021-08-30 14:00:05 +02:00
parent ff29c83d56
commit ff1be787f2
23 changed files with 61 additions and 61 deletions

29
api/time.go Normal file
View file

@ -0,0 +1,29 @@
package api
import (
"strings"
"time"
)
// Time is here to unmarshall time correctly
type Time struct {
time.Time
}
// UnmarshalJSON Parses Passbolt *Time
func (t *Time) UnmarshalJSON(buf []byte) error {
if string(buf) == "null" {
return nil
}
tt, err := time.Parse(time.RFC3339, strings.Trim(string(buf), `"`))
if err != nil {
return err
}
t.Time = tt
return nil
}
// MarshalJSON Marshals Passbolt *Time
func (t Time) MarshalJSON() ([]byte, error) {
return []byte(`"` + t.Time.Format(time.RFC3339) + `"`), nil
}