From 4a23134e1e5d70a9c8c5857790dbf27585ca3b1f Mon Sep 17 00:00:00 2001 From: Jeroen Wijenbergh Date: Fri, 29 Aug 2025 14:05:20 +0200 Subject: Discovery: Add cache argument and embed unmarshal on startup --- client/discovery.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'client/discovery.go') 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() } -- cgit v1.2.3