Documentation
¶
Index ¶
- Variables
- func DeleteProfile[T NamedProfile](p *Profiler, profileName string) error
- func GetGlobalConfig(p *Profiler) *global.Store
- func GetStoredProfile[T NamedProfile](profileStore *ProfileStore) (T, error)
- func HasGlobalStore(configName string, opts ...profileConfigVariadicFunc) (bool, error)
- func HasProfileStore(p *Profiler, profileName string) (bool, error)
- func ListProfiles(p *Profiler) []string
- func SetDefaultProfile(p *Profiler, profileName string) error
- func UpdateCurrentProfile(p *Profiler, profile NamedProfile) error
- func WithCustomStore(newCustomStore store.NewStoreInterface) profileConfigVariadicFunc
- func WithFileStore(storeDir string) profileConfigVariadicFunc
- func WithInMemoryStore() profileConfigVariadicFunc
- func WithKeyringStore() profileConfigVariadicFunc
- type NamedProfile
- type ProfileStore
- func GetCurrentProfile(p *Profiler) (*ProfileStore, error)
- func GetProfile[T NamedProfile](p *Profiler, profileName string) (*ProfileStore, error)
- func LoadProfileStore[T NamedProfile](serviceNamespace string, newStore store.NewStoreInterface, profileName string) (*ProfileStore, error)
- func NewProfileStore(serviceNamespace string, newStore store.NewStoreInterface, ...) (*ProfileStore, error)
- func RegisterProfile(p *Profiler, profile NamedProfile) (*ProfileStore, error)
- func UseDefaultProfile[T NamedProfile](p *Profiler) (*ProfileStore, error)
- func UseProfile[T NamedProfile](p *Profiler, profileName string) (*ProfileStore, error)
- func (p *ProfileStore) Delete() error
- func (p *ProfileStore) Extension(namespace string) (json.RawMessage, bool, error)
- func (p *ProfileStore) Extensions() (map[string]json.RawMessage, error)
- func (p *ProfileStore) GetProfileName() string
- func (p *ProfileStore) Save() error
- func (p *ProfileStore) SetExtension(namespace string, payload json.RawMessage) error
- type Profiler
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetGlobalConfig returns the global configuration
func GetStoredProfile ¶
func GetStoredProfile[T NamedProfile](profileStore *ProfileStore) (T, error)
Generic wrapper for working with specific types
func HasGlobalStore ¶
HasGlobalStore checks if any profiles have been created for a specific store before.
func HasProfileStore ¶
HasProfileStore checks physical presence independently of the global index. It propagates lookup errors rather than treating an unreadable record as absent.
func ListProfiles ¶
ListProfiles returns a list of all profile names
func SetDefaultProfile ¶
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) 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 ¶
New creates a new Profile with the specified configuration options. The configName is required and must be unique to the application.
func Open ¶
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 ¶
Cleanup attempts to delete all profiles and resources from the profiler's underlying store.
func (*Profiler) DeleteAllProfiles ¶
Deletes all profiles for a given profiler.