Skip to content

Commit

Permalink
fix: format timestamp responses with RFC3339TimeFormat
Browse files Browse the repository at this point in the history
This fixes the rest of the s3reponse types to marshall the time
field in RFC3339TimeFormat when MarshalXML called.

Fixes #782
  • Loading branch information
benmcclelland committed Sep 7, 2024
1 parent 66a7879 commit 3bf8b29
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions s3response/s3response.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ type GetObjectAttributesResult struct {
ObjectParts *ObjectParts
}

func (r GetObjectAttributesResult) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type Alias GetObjectAttributesResult
aux := &struct {
LastModified *string `xml:"LastModified"`
*Alias
}{
Alias: (*Alias)(&r),
}

if r.LastModified != nil {
formattedTime := r.LastModified.Format(RFC3339TimeFormat)
aux.LastModified = &formattedTime
}

return e.EncodeElement(aux, start)
}

type ObjectParts struct {
PartNumberMarker int
NextPartNumberMarker int
Expand Down Expand Up @@ -261,6 +278,20 @@ type ListAllMyBucketsEntry struct {
CreationDate time.Time
}

func (r ListAllMyBucketsEntry) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type Alias ListAllMyBucketsEntry
aux := &struct {
CreationDate string `xml:"LastModified"`
*Alias
}{
Alias: (*Alias)(&r),
}

aux.CreationDate = r.CreationDate.Format(RFC3339TimeFormat)

return e.EncodeElement(aux, start)
}

type ListAllMyBucketsList struct {
Bucket []ListAllMyBucketsEntry
}
Expand All @@ -276,6 +307,20 @@ type CopyObjectResult struct {
ETag string
}

func (r CopyObjectResult) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type Alias CopyObjectResult
aux := &struct {
LastModified string `xml:"LastModified"`
*Alias
}{
Alias: (*Alias)(&r),
}

aux.LastModified = r.LastModified.Format(RFC3339TimeFormat)

return e.EncodeElement(aux, start)
}

type AccessControlPolicy struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"`
Owner CanonicalUser
Expand Down

0 comments on commit 3bf8b29

Please sign in to comment.