Skip to content

viper cannot be used in init function, Right? #1279

Answered by sagikazarmark
pplmx asked this question in Q&A
Discussion options

You must be logged in to vote

Well, there is nothing that keeps you from using it in an init function, but if there is nothing available under a certain key, it will return nil.

Viper doesn't load files automatically. See the readme for examples.

Technically, the offending line is this: redisUrl := viper.Get("datasource.redis.url").(string)

You could change it to make the error go away, but it would still not return anything: redisUrl, ok := viper.Get("datasource.redis.url").(string)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pplmx
Comment options

Answer selected by pplmx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants