diff options
| author | Jeroen Wijenbergh <jeroen.wijenbergh@geant.org> | 2025-08-29 14:05:20 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <jeroen.wijenbergh@geant.org> | 2025-08-29 14:40:24 +0200 |
| commit | 4a23134e1e5d70a9c8c5857790dbf27585ca3b1f (patch) | |
| tree | c7edff437df88d6d127f8bda0a35d59fc0d3dc68 /client/discovery.go | |
| parent | 5461efc826952833fcdecca5d3daa3ee70423a31 (diff) | |
Discovery: Add cache argument and embed unmarshal on startup
Diffstat (limited to 'client/discovery.go')
| -rw-r--r-- | client/discovery.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/client/discovery.go b/client/discovery.go index b434025..802fe48 100644 --- a/client/discovery.go +++ b/client/discovery.go @@ -19,7 +19,8 @@ func (c *Client) hasDiscovery() bool { // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#organization-list. -func (c *Client) DiscoOrganizations(ck *cookie.Cookie, search string) (*discotypes.Organizations, error) { +// cache is set to true if there should be no network call done +func (c *Client) DiscoOrganizations(ck *cookie.Cookie, cache bool, search string) (*discotypes.Organizations, error) { // Not supported with Let's Connect! & govVPN if !c.hasDiscovery() { return nil, i18nerr.NewInternal("Organization discovery with this client ID is not supported") @@ -28,7 +29,7 @@ func (c *Client) DiscoOrganizations(ck *cookie.Cookie, search string) (*discotyp disco, release := c.discoMan.Discovery(true) defer release() - orgs, fresh, err := disco.Organizations(ck.Context()) + orgs, fresh, err := disco.Organizations(ck.Context(), cache) if fresh { defer c.TrySave() } @@ -68,7 +69,8 @@ func (c *Client) DiscoOrganizations(ck *cookie.Cookie, search string) (*discotyp // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#server-list. -func (c *Client) DiscoServers(ck *cookie.Cookie, search string) (*discotypes.Servers, error) { +// the cache argument is true if no network call should be done +func (c *Client) DiscoServers(ck *cookie.Cookie, cache bool, search string) (*discotypes.Servers, error) { // Not supported with Let's Connect! & govVPN if !c.hasDiscovery() { return nil, i18nerr.NewInternal("Server discovery with this client ID is not supported") @@ -76,7 +78,7 @@ func (c *Client) DiscoServers(ck *cookie.Cookie, search string) (*discotypes.Ser disco, release := c.discoMan.Discovery(true) defer release() - servs, fresh, err := disco.Servers(ck.Context()) + servs, fresh, err := disco.Servers(ck.Context(), cache) if fresh { defer c.TrySave() } |
