config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultConfigDir is the default directory for pkit configuration
	DefaultConfigDir = ".pkit"

	// ConfigFileName is the name of the configuration file
	ConfigFileName = "config.yml"
)
View Source
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

func CheckAndWarnRateLimit(rateLimit *models.RateLimit, threshold int)

CheckAndWarnRateLimit checks the rate limit and prints a warning if the threshold is exceeded. Returns the rate limit information.

func CheckConfigIntegrity

func CheckConfigIntegrity(path string) (warnings []string, err error)

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

func ExtractRateLimitFromResponse(resp *http.Response, authenticated bool) *models.RateLimit

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

func GetConfigPath() (string, error)

GetConfigPath returns the full path to the configuration file. It uses ~/.pkit/config.yml by default.

func GetGitHubToken

func GetGitHubToken() (string, error)

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

func GetIndexPath() (string, error)

GetIndexPath returns the full path to the index directory. It uses ~/.pkit/index by default.

func GetSourcesPath

func GetSourcesPath() (string, error)

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

func Load() (*models.Config, error)

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

func Save(cfg *models.Config) error

Save writes the configuration to ~/.pkit/config.yml using atomic write. Uses a temporary file and rename to ensure atomicity.

func SaveRateLimitToConfig

func SaveRateLimitToConfig(cfg *models.Config, rateLimit *models.RateLimit) error

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

func SetGitHubToken(token string) error

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

func ValidateAndFixConfig(cfg *models.Config) (*models.Config, error)

ValidateAndFixConfig validates the config and attempts to fix common issues. Returns the fixed config and any errors that couldn't be fixed.

func ValidateConfig

func ValidateConfig(cfg *models.Config) error

ValidateConfig validates a Config struct. This is a convenience wrapper around models.Config.Validate().

func ValidateConfigFile

func ValidateConfigFile(path string) error

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.

Jump to

Keyboard shortcuts

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