Files
tailscale/client/local/pins.go
Will HannahandWill Hannah e1ffeeffba client,feature/favorites: add locally-pinned favorites (#20563)
Let clients pin favorite devices, exit nodes, and services so GUIs can
surface & change them. Pins are stored per login profile in the new
favorites feature module, keyed per category; devices and exit nodes by
StableNodeID, services by ServiceName.

The item types live in a leaf package feature/favorites/pintype,
keeping them out of the core ipn hierarchy. Each category has
its own type (pintype.Device, pintype.ExitNode, pintype.Service).

Exposed over LocalAPI at GET/POST /localapi/v0/pins, where POST replaces
only the categories named in the request so a client can update one
category without clobbering the others. Pins are local to the device and
are not synced across a user's devices.

updates tailscale/corp#44836

Signed-off-by: Will Hannah <willh@tailscale.com>
Co-authored-by: Will Hannah <wph@Wills-Virtual-Machine.local>
2026-08-19 09:52:56 -04:00

42 lines
1.4 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_favorites
package local
import (
"context"
"net/http"
"tailscale.com/feature/favorites/pintype"
)
// GetPins returns the current profile's locally-pinned favorites.
//
// Pins are not currently announced over the IPN notification bus, including when they change
// because the backend switched to a different profile. The client is responsible for re-fetching
// pins on IPN state changes (e.g. profile switches) rather than assuming a previously fetched
// [pintype.Set] still applies.
//
// API maturity: this method is not considered a stable API and is subject to change between releases.
func (lc *Client) GetPins(ctx context.Context) (pintype.Set, error) {
body, err := lc.get200(ctx, "/localapi/v0/pins")
if err != nil {
return pintype.Set{}, err
}
return decodeJSON[pintype.Set](body)
}
// SetPins replaces the categories named in req for the current profile and returns the full updated
// pinned favorites.
//
// API maturity: this method is not considered a stable API and is subject to change between releases.
func (lc *Client) SetPins(ctx context.Context, req pintype.SetRequest) (pintype.Set, error) {
body, err := lc.send(ctx, "POST", "/localapi/v0/pins", http.StatusOK, jsonBody(req))
if err != nil {
return pintype.Set{}, err
}
return decodeJSON[pintype.Set](body)
}