util

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBurstCap int = 10

DefaultBurstCap is the default instance burst capacity. Lower than the GTS default of 300.

View Source
const DefaultRateLimit float64 = 0.5

DefaultRateLimit is the default instance rate limit. Lower than the GTS default of 1.0.

View Source
const DefaultScheme = "https"

DefaultScheme is the default instance URL scheme.

Variables

View Source
var CleartextFileKeyring keyring.Keyring

CleartextFileKeyring stores everything in a cleartext JSON file.

View Source
var HttpClient *http.Client
View Source
var PrefNotFound = errors.New("preference value not found")
View Source
var SystemKeyring keyring.Keyring

SystemKeyring forwards all operations to the go-keyring global system keyring.

View Source
var Website = "https://catgirl.codes/slurp"

Functions

func CheckArchiveFolder

func CheckArchiveFolder(archiveFolderPath string) error

func GetDefaultUser

func GetDefaultUser() (string, error)

func GetInstanceBurstCap

func GetInstanceBurstCap(instance string) (int, error)

func GetInstanceClientID

func GetInstanceClientID(instance string) (string, error)

func GetInstanceClientScopes

func GetInstanceClientScopes(instance string) (string, error)

func GetInstanceRateLimit

func GetInstanceRateLimit(instance string) (float64, error)

func GetInstanceScheme

func GetInstanceScheme(instance string) (string, error)

func GetUseCleartextFileKeyring

func GetUseCleartextFileKeyring() (bool, error)

func GetUserInstance

func GetUserInstance(user string) (string, error)

func IsEmpty

func IsEmpty(folderPath string) (bool, error)

IsEmpty returns whether a folder is empty.

func KeyringPath

func KeyringPath() string

KeyringPath returns the path to the keyring file, whether or not it exists yet.

func LoadJSON

func LoadJSON[T any](path string) (*T, error)

func PrefsPath

func PrefsPath() string

PrefsPath returns the path to the preferences file, whether or not it exists yet.

func Ptr

func Ptr[T any](v T) *T

func ReadCSV

func ReadCSV(file string) ([][]string, error)

ReadCSV reads CSV data from a file or stdout.

func RemoveExpectedCSVHeader

func RemoveExpectedCSVHeader(expectedHeader []string, rows [][]string) ([][]string, error)

RemoveExpectedCSVHeader checks that the CSV's header is a non-empty prefix of the expected header, and removes it from the rows.

func SaveJSON

func SaveJSON(path string, data any) error

func SavePrefs

func SavePrefs(prefs *Prefs) error

SavePrefs creates on-disk preferences or overwrites existing ones.

func SetDefaultUser

func SetDefaultUser(user string) error

func SetInstanceBurstCap

func SetInstanceBurstCap(instance string, burstCap int) error

func SetInstanceClientID

func SetInstanceClientID(instance string, clientID string) error

func SetInstanceClientScopes

func SetInstanceClientScopes(instance string, scopes string) error

func SetInstanceRateLimit

func SetInstanceRateLimit(instance string, rateLimit float64) error

func SetInstanceScheme

func SetInstanceScheme(instance string, scheme string) error

func SetUseCleartextFileKeyring

func SetUseCleartextFileKeyring(value bool) error

func SetUserInstance

func SetUserInstance(user string, instance string) error

func WriteCSV

func WriteCSV(file string, rows [][]string) error

WriteCSV writes CSV data to a file or stdout.

Types

type Prefs

type Prefs struct {
	// Instances is a map of instance names to instance preferences.
	Instances map[string]PrefsInstance `json:"instances,omitempty"`
	// Users is a map of user usernames@domains to instance data.
	Users map[string]PrefsUser `json:"users,omitempty"`
	// DefaultUser is the username@domain of the last user we successfully authenticated as,
	// if there is one.
	DefaultUser string `json:"default_user,omitempty"`
	// UseCleartextFileKeyring controls whether we use a file-backed keyring instead of a system keyring.
	UseCleartextFileKeyring bool `json:"use_cleartext_file_keyring,omitempty"`
}

Prefs stores persisted slurp preferences.

func LoadPrefs

func LoadPrefs() (*Prefs, error)

LoadPrefs returns preferences from disk or an empty prefs object if there are none stored or accessible.

type PrefsInstance

type PrefsInstance struct {
	// ClientID is the OAuth2 client ID for slurp on this instance.
	ClientID string `json:"client_id,omitempty"`

	// Scopes is the OAuth2 scopes this client was created with,
	// corresponding to the string oauthScopes in internal/auth/auth.go.
	// We use this to check if a previously created client has the right scopes for the current version of slurp.
	Scopes string `json:"scopes,omitempty"`

	// Scheme is the URL scheme for this instance.
	Scheme string `json:"scheme,omitempty"`

	// RateLimit is the rate limit for requests to this instance, in requests per second.
	RateLimit float64 `json:"rate_limit,omitempty"`

	// RateLimit is the burst capacity for requests to this instance, in requests at once.
	BurstCap int `json:"burst_cap,omitempty"`
}

PrefsInstance stores preferences for a given instance. OAuth2 app secrets are stored in the system keychain.

type PrefsUser

type PrefsUser struct {
	// Instance is the name of the instance that the user is on.
	Instance string `json:"instance"`
}

PrefsUser stores preferences for a given user. User access tokens are stored in the system keychain.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL