Documentation
¶
Index ¶
- Constants
- func CheckAndWarnRateLimit(rateLimit *models.RateLimit, threshold int)
- func CheckConfigIntegrity(path string) (warnings []string, err error)
- func DeleteGitHubToken() error
- func EnsureConfigDir() error
- func ExtractRateLimitFromResponse(resp *http.Response, authenticated bool) *models.RateLimit
- func GetConfigPath() (string, error)
- func GetGitHubToken() (string, error)
- func GetIndexPath() (string, error)
- func GetSourcesPath() (string, error)
- func HasGitHubToken() bool
- func Load() (*models.Config, error)
- func Save(cfg *models.Config) error
- func SaveRateLimitToConfig(cfg *models.Config, rateLimit *models.RateLimit) error
- func SetGitHubToken(token string) error
- func ValidateAndFixConfig(cfg *models.Config) (*models.Config, error)
- func ValidateConfig(cfg *models.Config) error
- func ValidateConfigFile(path string) error
Constants ¶
const ( // DefaultConfigDir is the default directory for pkit configuration DefaultConfigDir = ".pkit" // ConfigFileName is the name of the configuration file ConfigFileName = "config.yml" )
const ( // KeyringService is the service name for storing tokens in the system keyring KeyringService = "pkit" // KeyringUser is the username for the token entry KeyringUser = "github" // EnvVarToken is the environment variable name for the GitHub token fallback EnvVarToken = "GITHUB_TOKEN" )
Variables ¶
This section is empty.
Functions ¶
func CheckAndWarnRateLimit ¶
CheckAndWarnRateLimit checks the rate limit and prints a warning if the threshold is exceeded. Returns the rate limit information.
func CheckConfigIntegrity ¶
CheckConfigIntegrity performs a comprehensive integrity check on the config file. Returns a list of warnings (non-fatal issues) and any fatal errors.
func DeleteGitHubToken ¶
func DeleteGitHubToken() error
DeleteGitHubToken removes the GitHub personal access token from the system keyring. Returns an error if the keyring is not available or the operation fails. Returns nil if the token doesn't exist (idempotent).
func EnsureConfigDir ¶
func EnsureConfigDir() error
EnsureConfigDir ensures the configuration directory exists. Creates ~/.pkit/ if it doesn't exist.
func ExtractRateLimitFromResponse ¶
ExtractRateLimitFromResponse extracts rate limit information from GitHub API response headers. Returns a RateLimit struct with the extracted information, or nil if headers are missing.
func GetConfigPath ¶
GetConfigPath returns the full path to the configuration file. It uses ~/.pkit/config.yml by default.
func GetGitHubToken ¶
GetGitHubToken retrieves the GitHub personal access token. It first tries to read from the system keyring, then falls back to the GITHUB_TOKEN environment variable. Returns an empty string if no token is found (not an error - allows unauthenticated requests).
func GetIndexPath ¶
GetIndexPath returns the full path to the index directory. It uses ~/.pkit/index by default.
func GetSourcesPath ¶
GetSourcesPath returns the full path to the sources directory. It uses ~/.pkit/sources by default.
func HasGitHubToken ¶
func HasGitHubToken() bool
HasGitHubToken checks if a GitHub token is available (either in keyring or environment). Returns true if a token is found, false otherwise.
func Load ¶
Load reads and parses the configuration file from ~/.pkit/config.yml. Returns a default configuration if the file doesn't exist. Returns an error if the file exists but cannot be read or parsed.
func Save ¶
Save writes the configuration to ~/.pkit/config.yml using atomic write. Uses a temporary file and rename to ensure atomicity.
func SaveRateLimitToConfig ¶
SaveRateLimitToConfig updates the rate limit in the config and saves it. This is optional - rate limit can be ephemeral, but persisting helps with status display.
func SetGitHubToken ¶
SetGitHubToken stores the GitHub personal access token in the system keyring. Returns an error if the keyring is not available or the operation fails.
func ValidateAndFixConfig ¶
ValidateAndFixConfig validates the config and attempts to fix common issues. Returns the fixed config and any errors that couldn't be fixed.
func ValidateConfig ¶
ValidateConfig validates a Config struct. This is a convenience wrapper around models.Config.Validate().
func ValidateConfigFile ¶
ValidateConfigFile validates the configuration file at the given path. Returns an error if the file is corrupted or contains invalid data. Returns nil if the file doesn't exist (will use default config).
Types ¶
This section is empty.