storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/bucket/lifecycle/prefix.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package lifecycle
    18  
    19  import (
    20  	"encoding/xml"
    21  )
    22  
    23  // Prefix holds the prefix xml tag in <Rule> and <Filter>
    24  type Prefix struct {
    25  	string
    26  	set bool
    27  }
    28  
    29  // UnmarshalXML - decodes XML data.
    30  func (p *Prefix) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
    31  	var s string
    32  	if err = d.DecodeElement(&s, &start); err != nil {
    33  		return err
    34  	}
    35  	*p = Prefix{string: s, set: true}
    36  	return nil
    37  }
    38  
    39  // MarshalXML - decodes XML data.
    40  func (p Prefix) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error {
    41  	if !p.set {
    42  		return nil
    43  	}
    44  	return e.EncodeElement(p.string, startElement)
    45  }
    46  
    47  // String returns the prefix string
    48  func (p Prefix) String() string {
    49  	return p.string
    50  }