cost 348 ms
寫入 YAML 時 Viper 未使用的 mapstructure 標簽

[英]mapstructure tags not used by Viper when writing to YAML

我的結構定義如下 我正在寫一個 YAML 配置文件如下 我定義的mapstructure標簽並沒有寫到YAML文件中,而是將字段名寫成小寫。 這尤其是EnforcedProvider字段的問題,它被寫為enforcedprovider而不是enforced-provider 。 我該怎么做才能使用 ...

2022-12-05 18:10:35   1   36    go / viper-go  
Golang:從文件和環境變量加載配置

[英]Golang: Load config from file & environment variables

我正在使用毒蛇 package 從文件加載配置。 我的配置文件如下所示: 我想將數據庫名稱、數據庫用戶名、數據庫用戶密碼等秘密變量配置到環境變量中。 使用另一個普通變量,我可以直接在這個文件中配置,沒關系。 這是我的代碼: 這是我的.env 但它不起作用,我無法同時讀取 yaml 和環境配置。 數據 ...

2022-11-29 17:56:16   1   113    go / viper-go  
如何使用 Go Viper package 解組配置條目 header?

[英]How to unmarshall config entry header with Go Viper package?

我有一個如下所示的配置文件: 我正在使用 Viper 加載和讀取配置文件。 我正在解組上述配置並將其映射到以下結構: 我試圖解決的問題是獲取條目 header(即 customer1 和 customer2),而不必在我的配置文件中有一個冗余字段並以: ...

2022-10-07 14:39:43   1   29    go / viper-go  
Golang:AWS Lambda:找不到 spf13/viper 配置文件:配置文件“<config-file-name> “在“[/var/task /var/config]”中找不到</config-file-name>

[英]Golang: AWS Lambda: Fails finding spf13/viper config file: Config File "<config-file-name>" Not Found in "[/var/task /var/config]"

Golang 版本:1.18.5 配置庫: “github.com/spf13/viper” github 回購我正在編寫AWS Lambda使用Go。它位於AWS Apigateway后面,作為REST 881000512133388。 發現spf13/viper庫可用於該要求。 這是我的源代 ...

viper 不會從 env 或 pflags 解組值

[英]viper does not unmarshal values neither from env or pflags

我有以下非常簡單的go程序 package main import ( "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" ) type Config struct { AFlag string `ma ...

無法從 env 獲取嵌套密鑰以使用 viper 覆蓋 yaml 配置文件

[英]Can't get nested key from env to override yaml config file using viper

這是我的簡化配置: 為什么毒蛇不從環境中獲取價值? 我希望它從 env 中獲得價值,因為我有一個這樣的: 這是代碼: 我嘗試viper.BindEnv("STRIPE_SECRET_KEY")和viper.SetEnvPrefix("STRIPE")但沒有奏效。 ...

2022-05-28 10:04:32   1   160    go / viper-go  
讀取配置文件時出錯。 Golang 使用毒蛇 package

[英]Error reading config file. Golang using viper package

我需要幫助閱讀 env.json 文件。 任何時候我運行我的代碼我總是得到這個錯誤Error reading config file, Config File "env" Not Found in "[/Users/franklynomonade/go/src/bitbucket.org/core ...

2022-04-11 13:05:44   1   1486    go / viper-go  
有條件地將毒蛇配置(toml)解組為結構的慣用方法

[英]Idiomatic way to conditionally unmarshal a viper config (toml) into structs

我是 Go 的新手,想知道如何以慣用的方式解決以下問題: 我正在使用 viper 將配置文件加載到程序中。 我選擇 toml 格式是因為我想要一個配置文件,它可以指定幾種不同格式的所需輸入:例如,Alpha 提供程序需要一個 apikey,而 Beta 提供程序需要用戶名和密碼。type Provi ...

2022-01-27 20:15:57   2   49    go / viper-go  
golang:如何使用 viper 但沒有 cobra 支持 cli 參數、環境變量和配置文件?

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

我正在嘗試編寫一個只有一個命令的應用程序,因此,我想我可能會跳過 Cobra。 該應用程序應該能夠支持所有類型的配置: 命令行參數環境變量配置文件我正在使用 viper,但我無法讓它讀取我的 cli 參數。 但是我從來沒有將 cli 參數放入 conf 結構中。 在Unmarshal之前打印v不會 ...

目錄變量,但調用時出錯

[英]Variable for a directory but get error when calling it

我正在嘗試分配一個變量來讀取目錄,但出現此錯誤: “不能在 viper.AddConfigPath 的參數中使用 &amp;home(*[]fs.FileInfo 類型的值)作為字符串值” 我也嘗試了viper.AddConfigPath(&amp;home)中的指針,但也無濟於事這是代碼片段:/ ...

2021-12-29 11:34:49   3   40    go / viper-go  
在 Go 應用程序中使用 Viper 並確保測試和運行時都正常工作

[英]Use Viper in a Go app and make sure both tests and runtime work

我有以下文件夾結構 所以my-app.env是一個包含一些環境值的文件,它與包含代碼的文件夾src處於同一級別。 the-file.go使用viper讀取my-app.env以獲取環境的值,代碼如下 這樣,如果我使用命令go test./...運行測試,一切正常。 不幸的是,如果我構建並運行該應用 ...

2021-12-27 14:02:42   1   15    go / viper-go  
使用毒蛇解組 json 字符串以在 golang 中構造?

[英]use viper to unmarshall json string to struct in golang?

我從其他地方讀取配置,它返回一個 map 並且所有值都是字符串,並且不確定 Config.Mp map 中的哪個鍵,所以我想這樣做,但是在 Unmarshal 之后 Mp 為零,我怎么能用好方法嗎? 鈎子什么的? 謝謝~type DB struct { Name string `map ...

2021-12-10 02:34:18   1   25    go / viper-go  
viper.AutomaticEnv() 獲取環境變量無法正常工作

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

我試圖通過設置環境變量將開發配置文件與生產配置隔離開來。 操作系統: MAC OS ,我通過添加export DEBUG = True通過.bash_profile設置環境變量DEBUG = true 。 echo $debug得到正確的值true 。 我使用viper編寫了一個 function ...

2021-11-05 14:23:38   2   707    go / viper-go  
使用 Cobra 和 Viper 在 Go 中配置默認​​目錄路徑

[英]Configure a default directory path in Go with Cobra and Viper

我希望我的 CLI 應用程序的用戶輸入他們想要保存文件的特定路徑。 我嘗試使用 Cobra 的 --config 標志,但我不知道如何使用。 例子: app --config path "~/Documents/" 我怎么能這樣做? ...

viper 動態加載配置文件有數據競爭

[英]viper dynamically loading config file has data race

我想動態加載配置文件而不是重新啟動我的 Go 應用程序。 我寫了下面的文件,它運行但有數據競爭。 配置文件 main.go 配置文件 config_base.yml 去.mod 我最近了解到 viper 不是線程安全的,因此我需要用互斥鎖包裝它。 我也嘗試這樣做。 在 co ...

如何使用結構迭代 yml 部分?

[英]How to iterate over yml sections with structs?

我用毒蛇。 我正在嘗試使用 yml-config 從結構中獲取信息。 和 config.yml 我可以得到這樣的結構項目嗎? 我無法獲得這樣的聯系數據。 是否可以? ...

2021-07-16 09:53:31   2   80    go / viper-go  
在 Go 中使用 viper 讀取 bool 值

[英]reading bool value using viper in Go

我正在使用 viper 來管理 Go 應用程序的配置和環境變量。 所有值都來自 json 配置文件,期望 bool 值總是為假,即使它在 json 文件中具有真值 配置包 當我嘗試訪問任何字符串時,所有這些都是工作文件,但是當嘗試訪問 bool 變量時,它總是給出 false ...

在 Viper 中訪問嵌套 YAML 結構時出現問題

[英]Problem accessing nested YAML structure in Viper

最近用我的 Cobra 應用程序嘗試使用 Viper 來解析我的配置,但結果我無法解析內部嵌套塊。 ClustersOuter的 map 始終為空,我確信地圖結構已正確標記。 我更喜歡使用 Viper Unmarshall 功能而不是手動獲取數據類型。 Output 不知何故,我似乎只能檢索zo ...

為什么我會根據調用 BindPFlag 的位置收到零指針錯誤?

[英]Why am I getting a nil pointer error depending on where I call BindPFlag?

我最近才開始使用 Go,並且在使用 Cobra 和 Viper 時遇到了一些我不確定我是否理解的行為。 這是您通過運行cobra init獲得的示例代碼的略微修改版本。 在main.go我有: 在cmd/root.go我有: 此代碼將在最終調用fmt.Printf時出現 nil 指針引用恐慌: 如 ...

Cobra:在不使用 package 全局變量的情況下為子命令提供上下文?

[英]Cobra: Providing context to subcommands without using package globals?

我使用cobra和viper編寫了一個簡單的 CLI 工具。 我最近一直在重構它以避免 package 全局變量,主要是因為事實證明它很難使用cobra init建議的布局進行測試。 代替... 我有更像的東西: 這實際上效果很好,並且使測試更容易從一組干凈的 cli 選項開始。 我在將 Vipe ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM