mirror of
https://github.com/spf13/viper.git
synced 2026-09-20 03:18:21 +00:00
docs: better file not found example, remove file not found interface
This commit is contained in:
committed by
Márk Sági-Kazár
parent
29eb8d3fc7
commit
00a9d5df73
@@ -132,8 +132,12 @@ You can handle the specific case where no config file is found like this:
|
||||
|
||||
```go
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Config file not found; ignore error if desired
|
||||
if errors.As(err, &viper.FileNotFoundError{}) {
|
||||
// Indicates an explicitly set config file is not found, such as with
|
||||
// using `viper.SetConfigFile`
|
||||
} else if errors.As(err, &viper.FileNotFoundFromSearchError{}) {
|
||||
// Indicates that no config file was found in any search path, such as
|
||||
// when using `viper.AddConfigPath`
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
}
|
||||
|
||||
@@ -6,16 +6,6 @@ import (
|
||||
|
||||
/* File look-up errors */
|
||||
|
||||
// FileLookupError is returned when Viper cannot resolve a configuration file.
|
||||
//
|
||||
// This is meant to be a common interface for all file look-up errors, occurring either because a
|
||||
// file does not exist or because it cannot find any file matching finder criteria.
|
||||
type FileLookupError interface {
|
||||
error
|
||||
|
||||
fileLookup()
|
||||
}
|
||||
|
||||
// ConfigFileNotFoundError denotes failing to find a configuration file from a search.
|
||||
//
|
||||
// Deprecated: This is wrapped by FileNotFoundFromSearchError, which should be used instead.
|
||||
|
||||
Reference in New Issue
Block a user