forked from mtusi2026/mtusi2026lab6
26 lines
578 B
Go
26 lines
578 B
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
DisplayName string `json:"display_name"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// MarshalJSON форматирует CreatedAt в RFC3339 без микросекунд.
|
|
func (u User) MarshalJSON() ([]byte, error) {
|
|
type Alias User
|
|
return json.Marshal(&struct {
|
|
Alias
|
|
CreatedAt string `json:"created_at"`
|
|
}{
|
|
Alias: Alias(u),
|
|
CreatedAt: u.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
|
|
})
|
|
}
|