aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/foldermap.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-06-21 22:13:03 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-22 10:55:25 +0200
commit822bd3620a456fefcdb828f2768c0677e4442f05 (patch)
treece304de9f3e88599b557c4c3576d2656a5831348 /worker/lib/foldermap.go
parent0f37a0ce2cdc07a090e33bbe53b1b67081cce741 (diff)
downloadaerc-822bd3620a456fefcdb828f2768c0677e4442f05.tar.gz
lib: parse query-map and folder-map files
Combine the query-map and folder-map parsing functionality. Add tests. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/lib/foldermap.go')
-rw-r--r--worker/lib/foldermap.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/worker/lib/foldermap.go b/worker/lib/foldermap.go
new file mode 100644
index 00000000..4fd15979
--- /dev/null
+++ b/worker/lib/foldermap.go
@@ -0,0 +1,34 @@
+package lib
+
+import (
+ "fmt"
+ "io"
+
+ "github.com/go-ini/ini"
+)
+
+func ParseFolderMap(r io.Reader) (map[string]string, []string, error) {
+ cfg, err := ini.Load(r)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ sec, err := cfg.GetSection("")
+ if err != nil {
+ return nil, nil, err
+ }
+
+ order := sec.KeyStrings()
+
+ for _, k := range order {
+ v, err := sec.GetKey(k)
+ switch {
+ case v.String() == "":
+ return nil, nil, fmt.Errorf("no value for key '%s'", k)
+ case err != nil:
+ return nil, nil, err
+ }
+ }
+
+ return sec.KeysHash(), order, nil
+}