diff options
| author | Konstantin Lebedev <lebedev_k@tochka.com> | 2021-10-14 01:35:33 +0500 |
|---|---|---|
| committer | Konstantin Lebedev <lebedev_k@tochka.com> | 2021-10-14 01:35:33 +0500 |
| commit | 9d6ffa0ea157259b813faeb5b1805df31fdcb69b (patch) | |
| tree | 0ef8de0c98e197442a41e8d2c8728e0e964be98e /weed/s3api/s3api_policy.go | |
| parent | be4b3ed509178b6464452cd91fb06718548f9307 (diff) | |
| download | seaweedfs-9d6ffa0ea157259b813faeb5b1805df31fdcb69b.tar.xz seaweedfs-9d6ffa0ea157259b813faeb5b1805df31fdcb69b.zip | |
GetBucketLifecycleConfigurationHandler
Diffstat (limited to 'weed/s3api/s3api_policy.go')
| -rw-r--r-- | weed/s3api/s3api_policy.go | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/weed/s3api/s3api_policy.go b/weed/s3api/s3api_policy.go index 20dac9564..4177d27f3 100644 --- a/weed/s3api/s3api_policy.go +++ b/weed/s3api/s3api_policy.go @@ -51,6 +51,24 @@ type Prefix struct { set bool } +// MarshalXML - decodes XML data. +func (p Prefix) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error { + if !p.set { + return nil + } + return e.EncodeElement(p.string, startElement) +} + +func (f Filter) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if err := e.EncodeToken(start); err != nil { + return err + } + if err := e.EncodeElement(f.Prefix, xml.StartElement{Name: xml.Name{Local: "Prefix"}}); err != nil { + return err + } + return e.EncodeToken(xml.EndElement{Name: start.Name}) +} + // And - a tag to combine a prefix and multiple tags for lifecycle configuration rule. type And struct { XMLName xml.Name `xml:"And"` @@ -62,18 +80,50 @@ type And struct { type Expiration struct { XMLName xml.Name `xml:"Expiration"` Days int `xml:"Days,omitempty"` - Date time.Time `xml:"Date,omitempty"` + Date ExpirationDate `xml:"Date,omitempty"` DeleteMarker ExpireDeleteMarker `xml:"ExpiredObjectDeleteMarker"` set bool } +// MarshalXML encodes expiration field into an XML form. +func (e Expiration) MarshalXML(enc *xml.Encoder, startElement xml.StartElement) error { + if !e.set { + return nil + } + type expirationWrapper Expiration + return enc.EncodeElement(expirationWrapper(e), startElement) +} + // ExpireDeleteMarker represents value of ExpiredObjectDeleteMarker field in Expiration XML element. type ExpireDeleteMarker struct { val bool set bool } +// MarshalXML encodes delete marker boolean into an XML form. +func (b ExpireDeleteMarker) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error { + if !b.set { + return nil + } + return e.EncodeElement(b.val, startElement) +} + +// ExpirationDate is a embedded type containing time.Time to unmarshal +// Date in Expiration +type ExpirationDate struct { + time.Time +} + +// MarshalXML encodes expiration date if it is non-zero and encodes +// empty string otherwise +func (eDate ExpirationDate) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error { + if eDate.Time.IsZero() { + return nil + } + return e.EncodeElement(eDate.Format(time.RFC3339), startElement) +} + // Transition - transition actions for a rule in lifecycle configuration. type Transition struct { XMLName xml.Name `xml:"Transition"` @@ -84,5 +134,14 @@ type Transition struct { set bool } +// MarshalXML encodes transition field into an XML form. +func (t Transition) MarshalXML(enc *xml.Encoder, start xml.StartElement) error { + if !t.set { + return nil + } + type transitionWrapper Transition + return enc.EncodeElement(transitionWrapper(t), start) +} + // TransitionDays is a type alias to unmarshal Days in Transition type TransitionDays int |
