-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (40 loc) · 1 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"time"
"gopkg.in/yaml.v3"
)
type Config struct {
Indexes []IndexConfig `yaml:"indexes"`
BatchSize int `yaml:"batch_size"`
EnableAsync bool `yaml:"enable_async"`
WaitTime int `yaml:"wait_time"`
}
func (c *Config) Parse(path string) error {
b, err := os.ReadFile(path)
if err != nil {
return err
}
return yaml.Unmarshal(b, c)
}
func (c *Config) Save(path string) error {
b, err := yaml.Marshal(&c)
if err != nil {
return err
}
return os.WriteFile(path, b, 0644)
}
type IndexConfig struct {
Source string `yaml:"source"`
Destination string `yaml:"destination"`
Primary string `yaml:"primary"`
SourcePrimary string `yaml:"source_primary"`
Searchable []string `yaml:"searchable"`
Filterable []string `yaml:"filterable"`
Sortable []string `yaml:"sortable"`
Cursor Cursor `yaml:"cursor"`
}
type Cursor struct {
Column string `yaml:"column"`
LastSync time.Time `yaml:"last_sync"`
}