Questions tagged [viper-go]

This tag is for questions related to the Go Viper package for reading configuration data from files and other sources.

Viper is a configuration package for Go. It supports reading configuration data from many formats (JSON, TOML, YAML, HCL, or Java properties) and other sources, like environment variables and command line flags, setting defaults and overriding them. Optionally, configuration files can be watched and reloaded whenever they change.

96 questions
1
vote
0 answers

Cannot update configuration file dynamically in go with viper package

I'm trying to dynamically load configuration file for my cli application built with go. I'm loading configuration variables from a toml file. I'm using viper package to load the configurations and directly store in a config struct that I have…
rangarajan
  • 143
  • 5
  • 17
1
vote
1 answer

How to unmarshall config entry header with Go Viper package?

I have a configuration file that looks like the following: apps: customer1: upload_path: "/opt/uploads/customer1" local_path: "/opt/ready/customer1" bucket: "b1" customer2: upload_path: /opt/uploads/customer2 …
user982599
  • 975
  • 13
  • 28
1
vote
0 answers

Cobra and Viper to edit config

I've got a basic config file that's mashalled and unmarshalled by viper to a struct. type Config struct { field1 string field2 string field3 string } I want to set up cobra to let me do myapp get field1 and myapp set field1 foo for…
XeroxDucati
  • 5,130
  • 2
  • 37
  • 66
1
vote
0 answers

Use viper to unmarshal embedded struct ptr

could you elaborate on how to unmarshal config with embedded struct ptr using viper? I have a config structure like so: type Config struct { ... TracingConfig *HttpTracingConfig `mapstructure:"tracing"` ... } type HttpTracingConfig…
1
vote
2 answers

viper does not unmarshal values neither from env or pflags

I have the following very simple go program package main import ( "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" ) type Config struct { AFlag string `mapstructure:"A_FLAG"` } var rootCmd = &cobra.Command{ Use: …
pkaramol
  • 16,451
  • 43
  • 149
  • 324
1
vote
1 answer

Error reading config file. Golang using viper package

please i need help in reading from an env.json file. Anytime i run my code i always get this error Error reading config file, Config File "env" Not Found in…
1
vote
2 answers

golang: how to support cli params, env vars and config file with viper but no cobra?

I am trying to write an app which only has one command, hence, I was thinking I might skip Cobra. The app should be able to support all types of config: command line params env vars config file I am using viper but I can't get it to read my cli…
transient_loop
  • 5,984
  • 15
  • 58
  • 117
1
vote
0 answers

Using Cobra and Viper for a Go CLI

I'm creating a CLI in Go and I've decided to use both Cobra and Viper for parsing cli parameters and config files. I looked all over for a way to use both cobra and viper to merge both the configuration file and the given CLI parameters. I've…
Ori Zerah
  • 89
  • 1
  • 7
1
vote
3 answers

viper.AutomaticEnv() gets environment variable doesn't work properly

I was trying to isolate the development config file from production config by setting a environment variable. Operating System: MAC OS, I set a environment variable DEBUG = true through .bash_profile by adding export DEBUG = True. echo $debug gets…
W.W.G
  • 93
  • 2
  • 6
1
vote
3 answers

Viper config file found on dev but not on production using Dockerfile

In normal development (included build binary) go finds the config.yaml file, but in production, when using a Dockerfile image, it does not. My project folder is: |-cmd |- server |- main.go |- server (executable when built) |-config …
desenV
  • 307
  • 1
  • 2
  • 11
1
vote
0 answers

Set default value of Cobra flag with Viper

I'm working on a Cobra-based app in Go and for one of my commands I'm defining a flag like this: func init() { myCmd.Flags().StringVarP(&project, "project", "p", "defaultProject", "Project name") } I also have a Viper set up in my root command…
Radoslav Stoyanov
  • 1,460
  • 5
  • 27
  • 40
1
vote
0 answers

How to setup cobra and viper for test configurations in golang

We have a binary we are starting which has several subcommands, all set up with cobra. And we want to use viper for configuration. So the initialization of this is setup according to the docs: func init() { cobra.OnInitialize(initConfig) …
transient_loop
  • 5,984
  • 15
  • 58
  • 117
1
vote
2 answers

Validating configurations files with viper

I was looking for a configuration parser for go and https://github.com/spf13/viper seems to come highly recommended. I am very surprised to find that configuration files are not validated by default. Viper parses files and extracts requested values…
Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
1
vote
0 answers

Config files and Golang or just beginner mistake

I have done a few tutorials in Go and wanted to try something much more relevant that is going to needed from me relatively soon. Im starting by looking at viper and cobra. I understand the config file is actually for viper to use and cobra is just…
ruck64
  • 145
  • 1
  • 10
1
vote
1 answer

why the "switch t := policy.Parameter.(type)" does not work with viper.Unmarshal()

I want to unmarshal several types from JSON and use the interface to represent the actual struct that it is different. But when I send the struct as interface{} it converts it to a map. The animal.json…
Toni.W
  • 113
  • 1
  • 2
  • 12