2015-10-27 03:37:03 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-10-27 03:37:03 -07:00
|
|
|
|
|
|
|
package config
|
|
|
|
|
2020-04-26 15:13:35 -07:00
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"sort"
|
|
|
|
)
|
2015-10-27 03:37:03 -07:00
|
|
|
|
|
|
|
type VersioningConfiguration struct {
|
|
|
|
Type string `xml:"type,attr" json:"type"`
|
|
|
|
Params map[string]string `json:"params"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InternalVersioningConfiguration struct {
|
|
|
|
Type string `xml:"type,attr,omitempty"`
|
|
|
|
Params []InternalParam `xml:"param"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InternalParam struct {
|
|
|
|
Key string `xml:"key,attr"`
|
|
|
|
Val string `xml:"val,attr"`
|
|
|
|
}
|
|
|
|
|
2015-10-27 03:53:42 -07:00
|
|
|
func (c VersioningConfiguration) Copy() VersioningConfiguration {
|
|
|
|
cp := c
|
|
|
|
cp.Params = make(map[string]string, len(c.Params))
|
|
|
|
for k, v := range c.Params {
|
|
|
|
cp.Params[k] = v
|
|
|
|
}
|
|
|
|
return cp
|
|
|
|
}
|
|
|
|
|
2015-10-27 03:37:03 -07:00
|
|
|
func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
var tmp InternalVersioningConfiguration
|
|
|
|
tmp.Type = c.Type
|
|
|
|
for k, v := range c.Params {
|
|
|
|
tmp.Params = append(tmp.Params, InternalParam{k, v})
|
|
|
|
}
|
2020-04-26 15:13:35 -07:00
|
|
|
sort.Slice(tmp.Params, func(a, b int) bool {
|
|
|
|
return tmp.Params[a].Key < tmp.Params[b].Key
|
|
|
|
})
|
2015-10-27 03:37:03 -07:00
|
|
|
|
|
|
|
return e.EncodeElement(tmp, start)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
|
|
var tmp InternalVersioningConfiguration
|
|
|
|
err := d.DecodeElement(&tmp, &start)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Type = tmp.Type
|
|
|
|
c.Params = make(map[string]string, len(tmp.Params))
|
|
|
|
for _, p := range tmp.Params {
|
|
|
|
c.Params[p.Key] = p.Val
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|