config

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAPIKeyNotConfigured is the error returned when the loaded profile is missing the api_key property
	ErrAPIKeyNotConfigured = errors.New("you have not configured your API key yet")
	// ErrApplicationIDNotConfigured is the error returned when the loaded profile is missing the application_id property
	ErrApplicationIDNotConfigured = errors.New("you have not configured your Application ID yet")

	// ErrCrawlerAPIKeyNotConfigured is the error returned when the loaded profile is missing the crawler_api_key property
	ErrCrawlerAPIKeyNotConfigured = errors.New("you have not configured your Crawler API key yet")
	// ErrCrawlerUserIDNotConfigured is the error returned when the loaded profile is missing the crawler_user_id property
	ErrCrawlerUserIDNotConfigured = errors.New("you have not configured your Crawler user ID yet")
)

Functions

func AdminAPIKey

func AdminAPIKey(input string) error

AdminAPIKey validates that a string looks like an Admin API key.

Types

type Config

type Config struct {
	ApplicationName string

	CurrentProfile Profile

	File string
}

Config handles all overall configuration for the CLI

func (*Config) ApplicationIDExists

func (c *Config) ApplicationIDExists(appID string) (bool, string)

ApplicationIDExists check if an application ID exists in any profiles

func (*Config) ConfiguredProfiles

func (c *Config) ConfiguredProfiles() []*Profile

ConfiguredProfiles return the profiles in the configuration file

func (*Config) Default

func (c *Config) Default() *Profile

Default returns the default profile

func (*Config) GetConfigFolder

func (c *Config) GetConfigFolder(xdgPath string) string

GetConfigFolder retrieves the folder where the configuration file is stored It searches for the xdg environment path first and will secondarily place it in the home directory

func (*Config) InitConfig

func (c *Config) InitConfig()

InitConfig reads in profiles file and ENV variables if set.

func (*Config) Profile

func (c *Config) Profile() *Profile

Profile returns the current profile

func (*Config) ProfileExists

func (c *Config) ProfileExists(appName string) bool

ProfileExists check if a profile with the given name exists

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns the list of name of the configured profiles

func (*Config) RemoveProfile

func (c *Config) RemoveProfile(name string) error

RemoveProfile remove a profile from the configuration

func (*Config) SetDefaultProfile

func (c *Config) SetDefaultProfile(name string) error

SetDefaultProfile set the default profile

type IConfig

type IConfig interface {
	InitConfig()

	ConfiguredProfiles() []*Profile
	ProfileNames() []string

	ProfileExists(name string) bool
	RemoveProfile(name string) error
	SetDefaultProfile(name string) error

	ApplicationIDExists(appID string) (bool, string)

	Profile() *Profile
	Default() *Profile
}

type Profile

type Profile struct {
	Name string

	ApplicationID string   `mapstructure:"application_id"`
	APIKey        string   `mapstructure:"api_key"`
	AdminAPIKey   string   `mapstructure:"admin_api_key"` // Legacy
	SearchHosts   []string `mapstructure:"search_hosts"`

	Default bool `mapstructure:"default"`
}

func (*Profile) Add

func (p *Profile) Add() error

Add add a profile to the configuration

func (*Profile) GetAPIKey added in v1.6.0

func (p *Profile) GetAPIKey() (string, error)

func (*Profile) GetAdminAPIKey

func (p *Profile) GetAdminAPIKey() (string, error)

func (*Profile) GetApplicationID

func (p *Profile) GetApplicationID() (string, error)

func (*Profile) GetCrawlerAPIKey added in v1.4.0

func (p *Profile) GetCrawlerAPIKey() (string, error)

GetCrawlerAPIKey returns the Crawler API key.

func (*Profile) GetCrawlerUserID added in v1.4.0

func (p *Profile) GetCrawlerUserID() (string, error)

GetCrawlerUserID returns the Crawler user ID.

func (*Profile) GetFieldName

func (p *Profile) GetFieldName(field string) string

func (*Profile) GetSearchHosts added in v1.3.5

func (p *Profile) GetSearchHosts() []string

func (*Profile) LoadDefault

func (p *Profile) LoadDefault()

Jump to

Keyboard shortcuts

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