playing with an efficient file sync tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

47 lines
1.1 KiB

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)
}