pref

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MPL-2.0 Imports: 2 Imported by: 4

Documentation

Overview

package pref provides types used when passing preferences to plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithPreferences

func WithPreferences(ctx context.Context, p Preferences) context.Context

WithPreferences returns a context.Context with p attacked.

Types

type Preferences

type Preferences interface {
	// Lookup looks up key in file, returning the unmarshalled value from the
	// file.
	Lookup(file, key string) (any, error)

	// SetDefault sets the default value for the given key in file.
	SetDefault(file, key string, dflt any) error
}

Preferences is a type passed to plugins that may be used to load and save user preferences. When referencing a file, it should just be a relative path without an extension. vidar will check its settings directories and known config formats in order to read and unmarshal the file.

func FromCtx

func FromCtx(ctx context.Context) Preferences

FromCtx returns the Preferences attached to ctx. It will panic if there is no value attached as the preferences for ctx.

The first thing vidar does when starting is attach preferences to the root context.Context, so a preferences value should always be available.

Jump to

Keyboard shortcuts

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