summaryrefslogtreecommitdiff
path: root/internal/discovery/discovery.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/discovery/discovery.go')
-rw-r--r--internal/discovery/discovery.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index b6fef6f..c7eae95 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -44,6 +44,7 @@ type Organization struct {
KeywordList discotypes.MapOrString `json:"keyword_list,omitempty"`
}
+// Score returns the levenshstein score for a search query `search` on the organizations
func (o *Organization) Score(search string) int {
return levenshtein.DiscoveryScore(search, o.DisplayName, o.KeywordList)
}
@@ -75,7 +76,7 @@ type Server struct {
SupportContact []string `json:"support_contact,omitempty"`
}
-// Matches returns if the search query `str` matches with this server
+// Score returns the score of the search query `str` on this server
func (s *Server) Score(search string) int {
return levenshtein.DiscoveryScore(search, s.DisplayName, s.KeywordList)
}
@@ -404,12 +405,16 @@ func (discovery *Discovery) Servers(ctx context.Context) (*Servers, bool, error)
return &discovery.ServerList, true, nil
}
+// UpdateServers updates the discovery servers to the new version
+// It does this by checking versions
func (discovery *Discovery) UpdateServers(other Discovery) {
if other.ServerList.Version >= discovery.ServerList.Version {
discovery.ServerList = other.ServerList
}
}
+// Copy creates a deep-copy for the discovery struct
+// It does this by marshalling and unmarshalling it as JSON
func (discovery *Discovery) Copy() (Discovery, error) {
var dest Discovery
b, err := json.Marshal(discovery)