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
0
votes
1 answer

Is it possible to map a prefixed list of env values into a map with Viper?

I have a dotenv file in the current format KEY_PATH=/keys LOG_LEVEL=WARNING DB_CUSTOMER1=dbone DB_CUSTOMER2=dbtwo I also have a struct in the form of type MyConfiguration struct { KeyPath string `mapstructure:"KEY_PATH"` …
Andrei Dascalu
  • 1,059
  • 2
  • 14
  • 26
0
votes
2 answers

Writing new key to configuration file with Viper

First easy project with Go here. Based on user input, I need to add new keys to my existing configuration file. I manage to read it correctly with Viper and use it throughout the application, but WriteConfig doesn't seem to work. Here's a snippet: …
Alberto Coletta
  • 1,563
  • 2
  • 15
  • 24
0
votes
0 answers

Unmarshaling viper config into another viper config

I have a viper config that has some fixed fields, and some dynamic fields. It looks like this: //always contains those keys a: 1 b: "2" c: true //those keys might change: params: x1: 111 x2: "222" I know I can unmarshal the params part into a…
lev
  • 3,986
  • 4
  • 33
  • 46
0
votes
1 answer

viper changing data type on set

I have folder with json files like: schema file1.json file2.json and I am trying to iterate and get all data from each file in map[string]interface{} and I am getting data in such type successfully. but when I store it to the viper config it…
Eugen Dubrovin
  • 888
  • 5
  • 15
0
votes
1 answer

How to access specific items in an array from Viper

I have a yaml file similar to the following: ComplexItemList: - Name: First Complex item Date: Whenever StructItemList: - Name: blah Data1: 0 Data2: Silly - Name: Yaddah Data1: 12 Data2: Blah-blah-blah - Name: Second Complex…
P.McSwain
  • 344
  • 4
  • 14
0
votes
1 answer

How to get at openapi server values

I have the following yaml openapi 3 config' for my servers: servers: - url: "localhost" description: "localhost development server" variables: port: default: ":10000" Getting at those values via viper is trivial…
glowkeeper
  • 209
  • 2
  • 11
0
votes
1 answer

Unmarshalling config files in go

I am trying to read a config in a json file using the viper library //config.json { "currency": { "btc": [{ "api_endpoint": "api.blockcypher.com/v1/btc/main/addrs/$address/balance", …
kosta
  • 4,302
  • 10
  • 50
  • 104
0
votes
1 answer

Map flags with words separated-by-dashes to camel_case config?

I have a config format that looks like below: type config struct { FooBar string `mapstructure:"foo_bar"` BazBot string `mapstructure:"baz_bot"` } And my Cobra based CLI has flags with dashes (e.g. --foo-bar=value1 --baz-bot=value2). Viper…
Philip Lombardi
  • 1,276
  • 2
  • 17
  • 26
0
votes
0 answers

Reading slice of maps with Golang viper

I am trying to read slice of maps with golang viper with the following code (suggested by: Reading a slice of maps with Golang Viper) package main import ( "bytes" "fmt" "github.com/davecgh/go-spew/spew" …
CCH
  • 1
  • 1
0
votes
0 answers

Is there a way to use the string interpolation technique for setting a specific viper key that holds a list?

I am trying to use viper to set a particular property. I am aware of the convenience syntax that allows setting a viper configuration property by using the "dot" notation to reference nested properties. viper.Set("something.else.list[0].property",…
cyberbeast
  • 678
  • 1
  • 12
  • 30
0
votes
1 answer

Golang viper, I can't get fields after MergeConfigMap

I'm working on Go project where I need to set up some configurations and for that I am using Viper. When I merge map with viper object I can't get individual config fields after, however when I do viper.AllSettings() I do get all the settings, for…
Bekmamat
  • 51
  • 2
  • 6
0
votes
1 answer

How is a Cobra Flag of type `StringToStringVar` access using Viper?

I am trying to develop an application in Go that accepts inputs on the command line as a string of key value pairs. To do this I am using StrngToStringVar from the Cobra library. I am also using Viper to bind these flags to configuration, however…
Russell Seymour
  • 1,333
  • 1
  • 16
  • 35
0
votes
1 answer

Viper is not considering the yaml tags in my structs on unmarshalling

when I use the Unmarshal method of viper to fill my config structs with the values in my yaml file, some of the struct fields became empty! I do it in this…
meshkati
  • 1,720
  • 2
  • 16
  • 29
0
votes
1 answer

How to get 2 flags from a make command cobra

how do i create a makefile that takes in 2 arguments? myapp written in go, uses cobra cli. has a command that takes in 2 arguments(flags). this works $ go build; myapp mycmd --flag1=myvalue1 --flag2=myvalue2 in my make file i have //makefile run: …
not_fubar_yet
  • 194
  • 15
0
votes
1 answer

How to use dynamic keys when parsing YAML with viper?

I have the following yml file: # config.yml items: name-of-item: # dynamic field source: ... destination: ... And I want to use viper to parse it, but name-of-item can be anything, so I'm not sure how to solve that. I know that I could…
Amanda Ferrari
  • 1,168
  • 5
  • 17
  • 30