config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: GPL-2.0, GPL-2.0-only Imports: 8 Imported by: 0

Documentation

Overview

Package config provides configuration management for the application.

Index

Constants

View Source
const (
	DefaultAPIURL           = "https://api.scanoss.com"
	DefaultTimeout          = 30 * time.Second
	DefaultMaxRetries       = 3
	DefaultRetryDelay       = 5 * time.Second
	DefaultCacheTTL         = 7 * 24 * time.Hour  // 7 days for pinned versions
	DefaultLatestCacheTTL   = 24 * time.Hour      // 24 hours for @latest
	DefaultMaxStaleCacheAge = 30 * 24 * time.Hour // 30 days for stale cache fallback
	MaxStaleCacheAge        = 90 * 24 * time.Hour // Maximum allowed: 90 days
)

Default configuration values.

View Source
const (
	// RootDirName is the root directory for SCANOSS configuration.
	RootDirName = ".scanoss"

	// AppDirName is the application-specific directory.
	AppDirName = "crypto-finder"

	// ConfigFileName is the configuration file name.
	ConfigFileName = "config.json"

	// CacheDirName is the cache directory name.
	CacheDirName = "cache"

	// RulesetsDirName is the rulesets cache directory name.
	RulesetsDirName = "rulesets"
)

Variables

This section is empty.

Functions

func GetAppDir

func GetAppDir() (string, error)

GetAppDir returns the path to the crypto-finder directory (~/.scanoss/crypto-finder) Creates the directory if it doesn't exist.

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the path to the cache directory (~/.scanoss/crypto-finder/cache) Creates the directory if it doesn't exist.

func GetConfigFilePath

func GetConfigFilePath() (string, error)

GetConfigFilePath returns the path to the config file (~/.scanoss/crypto-finder/config.json) Does not create the file if it doesn't exist.

func GetRootDir

func GetRootDir() (string, error)

GetRootDir returns the path to the SCANOSS root directory (~/.scanoss) Creates the directory if it doesn't exist.

func GetRulesetsDir

func GetRulesetsDir() (string, error)

GetRulesetsDir returns the path to the rulesets cache directory (~/.scanoss/crypto-finder/cache/rulesets) Creates the directory if it doesn't exist.

func ResetInstance

func ResetInstance()

ResetInstance resets the singleton instance. Only for testing purposes.

Types

type Config

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

Config manages application configuration.

func GetInstance

func GetInstance() *Config

GetInstance returns the singleton config instance.

func (*Config) GetAPIKey

func (c *Config) GetAPIKey() string

GetAPIKey returns the configured API key.

func (*Config) GetAPIURL

func (c *Config) GetAPIURL() string

GetAPIURL returns the configured API URL.

func (*Config) Initialize

func (c *Config) Initialize(apiKeyFlag, apiURLFlag string) error

Initialize loads configuration from multiple sources. Viper automatically handles priority (highest to lowest): 1. Set() calls (used for CLI flags) - highest 2. Environment variables (SCANOSS_API_KEY, SCANOSS_API_URL) 3. Config file (~/.scanoss/crypto-finder/config.json) 4. Defaults (SetDefault) - lowest

The order of setup below doesn't affect priority - viper handles it automatically.

func (*Config) SetAPIKey

func (c *Config) SetAPIKey(key string) error

SetAPIKey updates the API key and persists to config file.

func (*Config) SetAPIURL

func (c *Config) SetAPIURL(url string) error

SetAPIURL updates the API URL and persists to config file.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

Jump to

Keyboard shortcuts

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