summaryrefslogtreecommitdiff
path: root/internal/discovery
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-07-10 14:39:34 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-07-17 14:00:03 +0000
commita1879195a727d7b90347ed11f86d85fac6541df7 (patch)
treeef19423671009552181f759b4a9162e7d91bf82a /internal/discovery
parent7f8af5845ddec1816f93a2cb013f0818c19caab3 (diff)
Client + Discovery: Fetch dscovery at startup using DiscoveryStartup
With a manager that locks and copies such that no race conditions happen
Diffstat (limited to 'internal/discovery')
-rw-r--r--internal/discovery/discovery.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index 30ca801..231c12a 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -405,3 +405,24 @@ func (discovery *Discovery) Servers(ctx context.Context) (*Servers, bool, error)
}
return &discovery.ServerList, true, nil
}
+
+func (discovery *Discovery) UpdateServers(other Discovery) {
+ if other.ServerList.Version >= discovery.ServerList.Version {
+ discovery.ServerList = other.ServerList
+ }
+}
+
+func (discovery *Discovery) Copy() (Discovery, error) {
+ var dest Discovery
+ b, err := json.Marshal(discovery)
+ if err != nil {
+ return dest, err
+ }
+
+ err = json.Unmarshal(b, &dest)
+ if err != nil {
+ return dest, err
+ }
+
+ return dest, nil
+}