feat: Phase 2 - Sync infrastructure
- Created sync client for communicating with API server - Implemented conflict resolution strategies (last-write-wins, server-wins, client-wins) - Added offline change queue for queuing changes when server is unreachable - Implemented merge logic for local and remote task lists - Added conflict logging to sync_conflicts.log - Created bidirectional sync with pull/push operations - Extended Config struct with sync settings (URL, API key, client ID, strategy, offline queue) - Added SyncResult display with user-friendly output - Sync handlers already implemented in Phase 1 (GetChanges, PushChanges)
This commit is contained in:
@@ -16,6 +16,14 @@ type Config struct {
|
||||
ColorOutput bool `mapstructure:"color_output"`
|
||||
WeekStartDay string `mapstructure:"week_start_day"`
|
||||
DefaultDueTime string `mapstructure:"default_due_time"`
|
||||
|
||||
// Sync settings
|
||||
SyncEnabled bool `mapstructure:"sync_enabled"`
|
||||
SyncURL string `mapstructure:"sync_url"`
|
||||
SyncAPIKey string `mapstructure:"sync_api_key"`
|
||||
SyncClientID string `mapstructure:"sync_client_id"`
|
||||
SyncStrategy string `mapstructure:"sync_strategy"`
|
||||
SyncQueueOffline bool `mapstructure:"sync_queue_offline"`
|
||||
}
|
||||
|
||||
var globalConfig *Config
|
||||
@@ -79,6 +87,14 @@ func LoadConfig() (*Config, error) {
|
||||
v.SetDefault("week_start_day", "monday")
|
||||
v.SetDefault("default_due_time", "")
|
||||
|
||||
// Sync defaults
|
||||
v.SetDefault("sync_enabled", false)
|
||||
v.SetDefault("sync_url", "")
|
||||
v.SetDefault("sync_api_key", "")
|
||||
v.SetDefault("sync_client_id", "")
|
||||
v.SetDefault("sync_strategy", "last-write-wins")
|
||||
v.SetDefault("sync_queue_offline", true)
|
||||
|
||||
// Try to read existing config
|
||||
err = v.ReadInConfig()
|
||||
if err != nil {
|
||||
@@ -119,6 +135,14 @@ func SaveConfig(cfg *Config) error {
|
||||
v.Set("week_start_day", cfg.WeekStartDay)
|
||||
v.Set("default_due_time", cfg.DefaultDueTime)
|
||||
|
||||
// Sync settings
|
||||
v.Set("sync_enabled", cfg.SyncEnabled)
|
||||
v.Set("sync_url", cfg.SyncURL)
|
||||
v.Set("sync_api_key", cfg.SyncAPIKey)
|
||||
v.Set("sync_client_id", cfg.SyncClientID)
|
||||
v.Set("sync_strategy", cfg.SyncStrategy)
|
||||
v.Set("sync_queue_offline", cfg.SyncQueueOffline)
|
||||
|
||||
return v.WriteConfig()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user