summaryrefslogtreecommitdiff
path: root/internal/discovery
diff options
context:
space:
mode:
Diffstat (limited to 'internal/discovery')
-rw-r--r--internal/discovery/discovery.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index 4a9ab92..6b7b961 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "strings"
"time"
"github.com/eduvpn/eduvpn-common/internal/http"
@@ -34,6 +35,25 @@ type Organization struct {
// SecureInternetHome is the secure internet home server that belongs to this organization
// Omitted if none is defined
SecureInternetHome string `json:"secure_internet_home"`
+ // KeywordList is the list of keywords
+ // Omitted if none is defined
+ KeywordList discotypes.MapOrString `json:"keyword_list,omitempty"`
+}
+
+// Matches returns if the search query `str` matches with this organization
+func (s *Organization) Matches(str string) bool {
+ var catalog strings.Builder
+ for _, v := range s.DisplayName {
+ // length and nil error is returned
+ _, _ = catalog.WriteString(strings.ToLower(v))
+ _, _ = catalog.WriteString(" ")
+ }
+ for _, v := range s.KeywordList {
+ // length and nil error is returned
+ _, _ = catalog.WriteString(strings.ToLower(v))
+ _, _ = catalog.WriteString(" ")
+ }
+ return strings.Contains(catalog.String(), str)
}
// Servers are the list of servers from https://disco.eduvpn.org/v2/server_list.json
@@ -55,12 +75,30 @@ type Server struct {
AuthenticationURLTemplate string `json:"authentication_url_template,omitempty"`
// CountryCode is the country code for the server in case of secure internet, e.g. NL
CountryCode string `json:"country_code,omitempty"`
+ // KeywordList are the keywords of the server, omitted if empty
+ KeywordList discotypes.MapOrString `json:"keyword_list,omitempty"`
// PublicKeyList are the public keys of the server. Currently not used in this lib but returned by the upstream discovery server
PublicKeyList []string `json:"public_key_list,omitempty"`
// SupportContact is the list/slice of support contacts
SupportContact []string `json:"support_contact,omitempty"`
}
+// Matches returns if the search query `str` matches with this server
+func (s *Server) Matches(str string) bool {
+ var catalog strings.Builder
+ for _, v := range s.DisplayName {
+ // length and nil error is returned
+ _, _ = catalog.WriteString(strings.ToLower(v))
+ _, _ = catalog.WriteString(" ")
+ }
+ for _, v := range s.KeywordList {
+ // length and nil error is returned
+ _, _ = catalog.WriteString(strings.ToLower(v))
+ _, _ = catalog.WriteString(" ")
+ }
+ return strings.Contains(catalog.String(), str)
+}
+
// Discovery is the main structure used for this package.
type Discovery struct {
// The httpClient for sending HTTP requests