-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config file not found #390
Comments
I'm not sure but maybe try viper.SetConfigType("yaml")
viper.SetConfigName("config")
viper.AddConfigPath("/etc")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err)
} or try viper.SetConfigFile("config.yaml")
viper.AddConfigPath("/etc")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err)
} |
I confirm the issue with "not found" configuration. The proposed solution doesn't solve it. |
It looks that config name should be without any extension (viper.SetConfigName(...)) while the actual file should have any supported extension. Take a look into Line 1536 in d9cca5e
|
@nad2000 is correct. So viper will search, your filepaths + filename + extension:
Instead, what you could do is specify the file type yourself via: and pass in the absolute path to your config file via: or if the config file will always be in the same directory as main application: |
How much time did I waste on this!? It should be documented clearly that specifying what data serialization format your config file uses, will modify the name that is searched for by appending an extension to the file name. |
Message removed... I messed up with the folder names... 😥 |
Instead of using // set the config file type
viper.SetConfigType("yaml")
// specify where the config file is
viper.SetConfigFile("./config/config") // or viper.SetConfigFile("config/config"), doesn't matter
// read in config file and check your errors
if err := viper.ReadInConfig(); err != nil {
// handle errors
}
// confirm where the file has been read in from
fmt.Println(viper.ConfigFileUsed()) |
for me my conf file is at
this is because if you set ConfigFile it takes the file as the absolute path instead of searching for that file in the list of config paths Lines 1521 to 1534 in d9cca5e
|
any update now? |
Thanks!! I solve my issue with this reply |
Neither Get nor SetConfigFile is working for me. I keep getting 'no such file' |
Use this instead....
|
It's looks like |
But it doesn't work |
The same problem happen to me. I use following method solve it. viper.SetConfigType("yaml") |
You can add multiple
|
@sagikazarmark this should be reopened as I mistakenly marked #722 as solving #390 . Thanks to @andig (#722 (comment)) for bringing this to attention. |
Unfortunately, I can't really tell anymore what this issue is about, but I get the feeling it's rather a documentation problem than an actual bug in the code. |
Re-reading this thread it seems the problem might be in the |
Assume your configs file in |
It doesn't work for production version |
Works for me in production: _, filePath, _, _ := runtime.Caller(0)
configFile := filePath[:len(filePath)-9]
viper.SetConfigFile(configFile + string(filepath.Separator) + ".env")
err := viper.ReadInConfig() |
Just had following problem:(using an existing configfile "myConfig.json") v := viper.New()
v.SetConfigName("myConfig.json")
v.SetConfigType("json")
v.AddConfigPath(".")
err := v.ReadInConfig()
if err != nil {
log.Panicf("Fatal error config file: %s", err)
} Without "SetConfigType" the error is thrown ... v := viper.New()
v.SetConfigName("myConfig.json")
// v.SetConfigType("json") => Omitting setting config type, leads to error condition, unless config name contains extension
v.AddConfigPath(".")
err := v.ReadInConfig()
if err != nil {
log.Panicf("Fatal error config file: %s", err)
} Running: go version go1.14.2 windows/amd64 |
Worked in Win10 (using GoLand)!! 😃 // Set the file name of the configurations file
viper.SetConfigName("config")
// Set the configuration file type
viper.SetConfigType("yaml")
// Set the path to look for the configurations file
viper.AddConfigPath("./config")
// Find and read the config file
err := viper.ReadInConfig()
if err != nil {
fmt.Printf("Error reading config file, %s", err)
return err
} BTW |
Can confirm |
need to set up in this way, see: spf13/viper#390 (comment) also, only works for the layout for now, need to get other pages working with this config as well. when it's local, this also enables static file server.
* example secret usage * there is no need fot the go dependencies section * temp: ls and tree * install aws sdk * temp: fail the build on purpose * make the upload assets job depend on build * switch to Go 1.15.6 * Revert "temp: fail the build on purpose" This reverts commit bf12a3b. * ls s3 bucket * dryrun aws s3 sync * seperate it into multiline correctly see https://stackoverflow.com/a/62044610/463785 * multi-line didn't seem to work see https://github.com/tugberkugurlu/go-bloggy/pull/5/checks?check_run_id=1597645520 * remove dryrun * set up yaml config for assets need to set up in this way, see: spf13/viper#390 (comment) also, only works for the layout for now, need to get other pages working with this config as well. when it's local, this also enables static file server. * push page data to the pages with a container so that I can push the config to the pages * use AssetsUrl in appropirate places * use lowercase file path for css * set correct mime types see aws/aws-cli#1249 (comment) it seems like following ones are set to `application/octet-stream` - icons.woff2 - brand-icons.woff2 - brand-icons.woff - icons.woff * cat /etc/mime.types * Ubuntu 18.04.1 LTS doesn't seem to use ~/.mime.types see aws/aws-cli#1249 (comment) * use sudo correctly with pipe see https://unix.stackexchange.com/a/106666 * lowercase the image urls * support for ci config folder * set ci/config.yaml * Upload CI config.yml for Assets * docker build see https://github.com/marketplace/actions/build-and-push-docker-images also https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts * Download artifact to a specific directory * enable docker push * seperate docker deploy into its own workflow so that we can only run that for master builds.
…ithub: spf13/viper#390 . Worked before though? Very strange
How we handled this fckn problem? I m trying for 2 day . . . |
This was very frustrating to deal with. For me, I finally figured out that you cannot use SetConfigFile() in conjunction with anything else. It can only be the path to the config file. If you use this method, it will ignore any paths and ONLY use the value passed to SetConfigFile() In this example, my file is named fileNameNoExtension.yaml on disk.
if I uncomment the last line, all previous lines are ignored and the config file fails to resolve. |
Can successfully read my configuration after setting the var (
_, b, _, _ = runtime.Caller(0)
root = filepath.Join(filepath.Dir(b), "../..")
)
func main() {
viper.AddConfigPath(root)
viper.SetConfigType("yaml") // This work
viper.SetConfigName("my-config-file")
_ = viper.ReadInConfig()
... var (
_, b, _, _ = runtime.Caller(0)
root = filepath.Join(filepath.Dir(b), "../..")
)
func main() {
viper.AddConfigPath(root)
viper.SetConfigName("my-config-file.yaml") // This doesn't work
_ = viper.ReadInConfig()
... |
you need to ensure you only use one of the two approaches, either specify the file by the full config file name or let viper figure it out.
OR
So to read in the config file in YAML format placed at
OR
Here's a gist for some examples https://gist.github.com/gwvandesteeg/939c05ac34518d65c49a94b2dbdd7cec |
Still is broken. Wtf... |
it seems like doc is wrong
For me this one worked viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(...)
viper.AddConfigPath(...) this not viper.SetConfigName("config.yaml")
viper.AddConfigPath(...)
viper.AddConfigPath(...) |
I'm having the same issue, i tried all the methods above but none of them worked for me viper.SetConfigType("yaml")
viper.AddConfigPath("../configs")
viper.SetConfigName("config") |
Update your env AddConfigPath with ../env or ../../env |
hello,i code the example:
viper.SetConfigType("yaml")
//viper.SetConfigFile("/etc/config.yaml")
viper.SetConfigName("config.yaml")
viper.AddConfigPath("/etc")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err)
}
or
viper.SetConfigType("yaml")
viper.SetConfigFile("config.yaml")
//viper.SetConfigName("config.yaml")
viper.AddConfigPath("/etc")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err)
}
i'm sure that i have config.yaml in /etc dirctionary,but the outputs of these code are:
Config File "config.yaml" Not Found in "[/etc]"
open config.yaml: no such file or directory
what's wrong?
The text was updated successfully, but these errors were encountered: