Documentation
¶
Index ¶
- func ExpandPath(path string) string
- func GetConfigFilePath() string
- func InitConfig(configFile string) error
- func IsPathSafe(basePath, targetPath string) bool
- func IsUnderGitRepo(path string) bool
- func ResolveCacheDir() string
- func ResolveConfigDir() string
- func ResolveDataDir() string
- func ResolvePath(path, baseDir string) string
- func SafeOpen(basePath, filePath string) (*os.File, error)
- func SafeOpenFile(basePath, filePath string, flag int, perm os.FileMode) (*os.File, error)
- type Config
- type ConfigPaths
- type ConfigProject
- type Controller
- type ErrConfigNotFound
- type RunEFunc
- type TestEnv
- type UseCase
- type ViewModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandPath ¶ added in v0.16.0
ExpandPath expands environment variables and tilde in a path. - Environment variables: $VAR or %VAR% (cross-platform via os.ExpandEnv) - Tilde: ~ expands to user's home directory
func GetConfigFilePath ¶ added in v0.16.0
func GetConfigFilePath() string
GetConfigFilePath returns the path to the config file. If viper has a config file set, returns that. Otherwise returns default path.
func InitConfig ¶ added in v0.15.0
InitConfig initializes the global configuration. If the config file is not found, Cfg is initialized with defaults and ErrConfigNotFound is returned. The caller can check for this error type to decide whether to proceed without a config file.
func IsPathSafe ¶ added in v0.16.0
IsPathSafe checks if targetPath is safely contained within basePath. This prevents Zip Slip vulnerabilities by ensuring the target doesn't escape the base directory via ../ or similar path traversal.
func IsUnderGitRepo ¶ added in v0.16.0
IsUnderGitRepo checks if the given path is inside a git repository by traversing parent directories looking for .git directory.
func ResolveCacheDir ¶ added in v0.16.0
func ResolveCacheDir() string
ResolveCacheDir resolves the cache directory using fallback chain: 1. XDG_CACHE_HOME environment variable (all platforms) 2. Windows LOCALAPPDATA\cache (Windows only, when XDG not set) 3. Default XDG path (~/.cache)
func ResolveConfigDir ¶ added in v0.16.0
func ResolveConfigDir() string
ResolveConfigDir resolves the configuration directory using fallback chain: 1. XDG_CONFIG_HOME environment variable (all platforms) 2. Windows APPDATA (Windows only, when XDG not set) 3. Default XDG path (~/.config)
func ResolveDataDir ¶ added in v0.16.0
func ResolveDataDir() string
ResolveDataDir resolves the data directory using fallback chain: 1. XDG_DATA_HOME environment variable (all platforms) 2. Windows LOCALAPPDATA (Windows only, when XDG not set) 3. Default XDG path (~/.local/share)
func ResolvePath ¶ added in v0.16.0
ResolvePath resolves a path that may be relative to a base directory. - Absolute paths are returned as-is (after expansion) - Relative paths are resolved relative to baseDir - Environment variables and tilde are expanded first
Types ¶
type Config ¶
type Config struct {
LastUpdateCheckTimestamp time.Time `mapstructure:"last_update_check_timestamp"`
LastFormatTimestamp time.Time `mapstructure:"last_format_timestamp"`
Project ConfigProject `mapstructure:"project"`
Paths ConfigPaths `mapstructure:"path"`
// contains filtered or unexported fields
}
var Cfg *Config
func (*Config) GetCacheDir ¶
func (*Config) GetConfigDir ¶
func (*Config) GetDataDir ¶
func (*Config) LoadConfig ¶
func (*Config) ResetLastUpdateCheckTimestamp ¶ added in v0.10.1
func (c *Config) ResetLastUpdateCheckTimestamp()
func (*Config) SaveConfig ¶ added in v0.10.0
type ConfigPaths ¶ added in v0.16.0
type ConfigProject ¶ added in v0.14.0
type Controller ¶ added in v0.3.2
type ErrConfigNotFound ¶ added in v0.16.0
type ErrConfigNotFound struct {
Path string
}
ErrConfigNotFound is returned when the configuration file does not exist. This indicates the user should run 'nippo init' first.
func (*ErrConfigNotFound) Error ¶ added in v0.16.0
func (e *ErrConfigNotFound) Error() string
type TestEnv ¶ added in v0.16.1
type TestEnv struct {
TmpDir string
ConfigDir string
DataDir string
CacheDir string
// contains filtered or unexported fields
}
TestEnv holds the test environment configuration
func SetupTestEnv ¶ added in v0.16.1
SetupTestEnv creates an isolated test environment that prevents tests from reading or writing to the user's actual config files. It returns a TestEnv with paths to temporary directories and a cleanup function.
Usage:
func TestSomething(t *testing.T) {
env := core.SetupTestEnv(t)
defer env.Cleanup()
// ... test code ...
}
func (*TestEnv) Cleanup ¶ added in v0.16.1
func (e *TestEnv) Cleanup()
Cleanup removes the temporary test environment. This should be called with defer after SetupTestEnv.
func (*TestEnv) CreateConfigFile ¶ added in v0.16.1
CreateConfigFile creates a test config file with the given content.
func (*TestEnv) CreateCredentialsFile ¶ added in v0.16.1
CreateCredentialsFile creates a test credentials.json file.