This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
SyncRefs/config.go

48 lines
1.1 KiB
Go

package main
import (
"encoding/xml"
"io"
)
// Config is the over all body for mapping the references to be synchronized
type Config struct {
XMLName xml.Name `xml:"config"`
SyncRefs []SyncRef `xml:"refs>ref"`
Groups []Group `xml:"groups>group"`
}
// Group defines a set of references that changes will be propogated within
type Group struct {
XMLName xml.Name `xml:"group"`
ID string `xml:"id,attr"`
Active bool `xml:"active,attr"`
Contains []string `xml:"contains>refID"`
}
// SyncRef is a reference to a location to be synchronized from/to
type SyncRef struct {
XMLName xml.Name `xml:"ref"`
ID string `xml:"id,attr"`
URI string
ReadOnly bool
Deletes bool
}
// 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)
}