v0.1.38 d3a4767

refreshing.go RawHistoryFolder

1package provider
2
3import (
4	"context"
5	"sync"
6)
7
8// TokenRefresher is a callback that checks whether the current token
9// is still valid and returns a fresh one if needed. The returned
10// string is the new access token; if empty the old one is still fine.
11// An error means refresh failed (network down, refresh token expired,
12// etc.) — the caller should proceed with the stale token and let the
13// API return 401 naturally.
14type TokenRefresher func(ctx context.Context) (newToken string, err error)
15
16// RefreshingClient wraps a Client and calls a TokenRefresher before
17// every Stream call. When the refresher returns a new token, a fresh
18// underlying client is built via the factory function.
19type RefreshingClient struct {
20	mu      sync.Mutex
21	inner   Client
22	refresh TokenRefresher
23	factory func(token string) Client
24}
25
26// NewRefreshingClient wraps inner with automatic token refresh.
27// refreshFn is called before each Stream; if it returns a non-empty
28// token the factory rebuilds the underlying client with the new token.
29func NewRefreshingClient(inner Client, refreshFn TokenRefresher, factory func(token string) Client) *RefreshingClient {
30	return &RefreshingClient{
31		inner:   inner,
32		refresh: refreshFn,
33		factory: factory,
34	}
35}
36
37func (c *RefreshingClient) Name() string {
38	c.mu.Lock()
39	defer c.mu.Unlock()
40	return c.inner.Name()
41}
42
43func (c *RefreshingClient) Stream(ctx context.Context, req Request) (<-chan Event, error) {
44	if c.refresh != nil {
45		if newToken, err := c.refresh(ctx); err == nil && newToken != "" {
46			c.mu.Lock()
47			c.inner = c.factory(newToken)
48			c.mu.Unlock()
49		}
50		// On refresh error: proceed with the current client.
51		// The stale token will 401 and the user sees a clear error.
52	}
53	c.mu.Lock()
54	inner := c.inner
55	c.mu.Unlock()
56	return inner.Stream(ctx, req)
57}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close