profilestore

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: BSD-3-Clause-Clear, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidProfiler            = errors.New("error: profiler is uninitialized or closed")
	ErrProfileNameConflict        = errors.New("error: profile name already exists in storage")
	ErrMissingCurrentProfile      = errors.New("error: current profile not set")
	ErrMissingDefaultProfile      = errors.New("error: default profile not set")
	ErrMissingProfileName         = errors.New("error: profile name not found")
	ErrInvalidStoreDriver         = errors.New("error: invalid store driver")
	ErrDeletingProfile            = errors.New("error: deleting profile with name")
	ErrCannotDeleteDefaultProfile = errors.New("error: cannot delete default profile")
)

Functions

func DeleteProfile

func DeleteProfile[T NamedProfile](p *Profiler, profileName string) error

DeleteProfile removes a profile from storage

func GetGlobalConfig

func GetGlobalConfig(p *Profiler) *global.Store

GetGlobalConfig returns the global configuration

func GetStoredProfile

func GetStoredProfile[T NamedProfile](profileStore *ProfileStore) (T, error)

Generic wrapper for working with specific types

func HasGlobalStore

func HasGlobalStore(configName string, opts ...profileConfigVariadicFunc) (bool, error)

HasGlobalStore checks if any profiles have been created for a specific store before.

func HasProfileStore

func HasProfileStore(p *Profiler, profileName string) (bool, error)

HasProfileStore checks physical presence independently of the global index. It propagates lookup errors rather than treating an unreadable record as absent.

func ListProfiles

func ListProfiles(p *Profiler) []string

ListProfiles returns a list of all profile names

func SetDefaultProfile

func SetDefaultProfile(p *Profiler, profileName string) error

SetDefaultProfile sets the a specified profile to the default profile

func UpdateCurrentProfile

func UpdateCurrentProfile(p *Profiler, profile NamedProfile) error

UpdateProfile updates the current profile with new data

func WithCustomStore

func WithCustomStore(newCustomStore store.NewStoreInterface) profileConfigVariadicFunc

func WithFileStore

func WithFileStore(storeDir string) profileConfigVariadicFunc

func WithInMemoryStore

func WithInMemoryStore() profileConfigVariadicFunc

func WithKeyringStore

func WithKeyringStore() profileConfigVariadicFunc

Types

type NamedProfile

type NamedProfile interface {
	GetName() string
}

NamedProfile is the holder of a profile containing a name and all stored profile data. It is marshaled on Get and unmarshaled on Set, so an interface is used to allow for any struct to be stored. The struct satisfying the interface must have JSON tags for each stored field.

Example:

type MyProfile struct {
	 Name string `json:"name"`
	 Email string `json:"email"`
}

func (p *MyProfile) GetName() string {
 return p.Name
}

type ProfileStore

type ProfileStore struct {

	// Profile is the struct that holds the profile data and satisfies the NamedProfile interface.
	// Exported to allow write/read access to the profile data being stored.
	Profile NamedProfile
	// contains filtered or unexported fields
}

func GetCurrentProfile

func GetCurrentProfile(p *Profiler) (*ProfileStore, error)

GetCurrentProfile returns the current stored profile

func GetProfile

func GetProfile[T NamedProfile](p *Profiler, profileName string) (*ProfileStore, error)

GetProfile returns the profile store for the specified profile name

func LoadProfileStore

func LoadProfileStore[T NamedProfile](serviceNamespace string, newStore store.NewStoreInterface, profileName string) (*ProfileStore, error)

func NewProfileStore

func NewProfileStore(serviceNamespace string, newStore store.NewStoreInterface, profile NamedProfile) (*ProfileStore, error)

func RegisterProfile

func RegisterProfile(p *Profiler, profile NamedProfile) (*ProfileStore, error)

RegisterProfile creates and registers a profile without choosing a default. Unlike AddProfile, even the first registration preserves an empty default. A failed registration may leave an unregistered profile record; retries reject that collision rather than overwriting it. This is not a multi-record transaction.

func UseDefaultProfile

func UseDefaultProfile[T NamedProfile](p *Profiler) (*ProfileStore, error)

UseDefaultProfile sets the current profile to the default profile

func UseProfile

func UseProfile[T NamedProfile](p *Profiler, profileName string) (*ProfileStore, error)

UseProfile sets the current profile to the specified profile name

func (*ProfileStore) Delete

func (p *ProfileStore) Delete() error

Delete the current profile from the store

func (*ProfileStore) Extension

func (p *ProfileStore) Extension(namespace string) (json.RawMessage, bool, error)

func (*ProfileStore) Extensions

func (p *ProfileStore) Extensions() (map[string]json.RawMessage, error)

Extensions returns opaque payloads; missing extensions are represented by an empty map.

func (*ProfileStore) GetProfileName

func (p *ProfileStore) GetProfileName() string

Profile Name

func (*ProfileStore) Save

func (p *ProfileStore) Save() error

Save the current profile data to the store

func (*ProfileStore) SetExtension

func (p *ProfileStore) SetExtension(namespace string, payload json.RawMessage) error

SetExtension replaces one namespace in the latest persisted profile.

type Profiler

type Profiler struct {
	// contains filtered or unexported fields
}

Profiler is the main interface for managing profiles

func New

func New(configName string, opts ...profileConfigVariadicFunc) (*Profiler, error)

New creates a new Profile with the specified configuration options. The configName is required and must be unique to the application.

func Open

func Open(configName string, opts ...profileConfigVariadicFunc) (*Profiler, error)

Open reads a profiler without creating or version-saving global records. Drivers may create their storage directory, but no configuration is written.

func (*Profiler) AddProfile

func (p *Profiler) AddProfile(profile NamedProfile, setDefault bool) error

AddProfile adds a new profile to the current configuration

func (*Profiler) Cleanup

func (p *Profiler) Cleanup(forceDelete bool) error

Cleanup attempts to delete all profiles and resources from the profiler's underlying store.

func (*Profiler) DeleteAllProfiles

func (p *Profiler) DeleteAllProfiles() error

Deletes all profiles for a given profiler.

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

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