2016-10-13 20:48:57 +00:00
|
|
|
package main
|
|
|
|
|
2016-10-13 21:28:37 +00:00
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"io"
|
|
|
|
)
|
2016-10-13 20:48:57 +00:00
|
|
|
|
2016-10-13 21:28:37 +00:00
|
|
|
// Config is the over all body for mapping the references to be synchronized
|
2016-10-13 20:48:57 +00:00
|
|
|
type Config struct {
|
|
|
|
XMLName xml.Name `xml:"config"`
|
|
|
|
SyncRefs []SyncRef `xml:"refs>ref"`
|
|
|
|
Groups []Group `xml:"groups>group"`
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:28:37 +00:00
|
|
|
// Group defines a set of references that changes will be propogated within
|
2016-10-13 20:48:57 +00:00
|
|
|
type Group struct {
|
|
|
|
XMLName xml.Name `xml:"group"`
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
Active bool `xml:"active,attr"`
|
|
|
|
Contains []string `xml:"contains>refID"`
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:28:37 +00:00
|
|
|
// SyncRef is a reference to a location to be synchronized from/to
|
2016-10-13 20:48:57 +00:00
|
|
|
type SyncRef struct {
|
|
|
|
XMLName xml.Name `xml:"ref"`
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
URI string
|
|
|
|
ReadOnly bool
|
|
|
|
Deletes bool
|
|
|
|
}
|
2016-10-13 21:28:37 +00:00
|
|
|
|
|
|
|
// ReadConfig Parses a Config from an input
|
|
|
|
func ReadConfig(r io.Reader) (*Config, error) {
|
|
|
|
dec := xml.NewDecoder(r)
|
|
|
|
config := Config{}
|
|
|
|
if err := dec.Decode(&config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteConfig marshals the Config to output w
|
|
|
|
func WriteConfig(w io.Writer, config Config) error {
|
|
|
|
enc := xml.NewEncoder(w)
|
|
|
|
enc.Indent("", " ")
|
|
|
|
return enc.Encode(config)
|
|
|
|
}
|