summaryrefslogtreecommitdiff
path: root/client/token.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-12 19:18:05 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commit74e36f0ead717105f26087c2cab08b41ba5a7ce8 (patch)
tree1eb2b7516bea705c9b5a50ce0965e170414ed880 /client/token.go
parent682d70091af2044ff6d8b350da9dff13163232e2 (diff)
All: Document everything to pass revive lint
Diffstat (limited to 'client/token.go')
-rw-r--r--client/token.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/client/token.go b/client/token.go
index d62308b..03ec1d6 100644
--- a/client/token.go
+++ b/client/token.go
@@ -10,12 +10,17 @@ import (
type cacheMap map[string]eduoauth.Token
+// TokenCacher is a structure that caches tokens for each type of server
type TokenCacher struct {
+ // InstituteAccess is the cached map for institute access servers
InstituteAccess cacheMap
- CustomServer cacheMap
- SecureInternet *eduoauth.Token
+ // CustomServer is the cached map for custom server
+ CustomServer cacheMap
+ // SecureInternet is the cached map for the secure internet server
+ SecureInternet *eduoauth.Token
}
+// Get gets tokens from the cache map
func (c *cacheMap) Get(id string) (*eduoauth.Token, error) {
if c == nil || len(*c) == 0 {
return nil, errors.New("no cache map available")
@@ -26,6 +31,7 @@ func (c *cacheMap) Get(id string) (*eduoauth.Token, error) {
return nil, fmt.Errorf("identifier: '%s' does not exist in token cache map", id)
}
+// Get gets tokens using a server id and type from the cacher
func (tc *TokenCacher) Get(id string, t srvtypes.Type) (*eduoauth.Token, error) {
switch t {
case srvtypes.TypeCustom:
@@ -41,6 +47,7 @@ func (tc *TokenCacher) Get(id string, t srvtypes.Type) (*eduoauth.Token, error)
return nil, fmt.Errorf("invalid type for token cacher get: %d", t)
}
+// Set updates the cache for the server id `id` with tokens `t`
func (c *cacheMap) Set(id string, t eduoauth.Token) {
if c == nil || len(*c) == 0 {
*c = make(cacheMap)
@@ -48,6 +55,7 @@ func (c *cacheMap) Set(id string, t eduoauth.Token) {
(*c)[id] = t
}
+// Set updates the top-level cacher for a specific server type
func (tc *TokenCacher) Set(id string, t srvtypes.Type, tok eduoauth.Token) error {
switch t {
case srvtypes.TypeCustom: