1 回答
TA贡献2016条经验 获得超9个赞
您可以使用 viper 读取您的 .yaml 配置文件。简单代码示例:
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
readYaml()
}
func readYaml() {
viper.SetConfigName("test") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath("./Examples/readyaml") // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %w", err))
}
fmt.Println(viper.AllKeys())
for _, i := range viper.AllKeys() {
fmt.Println(i, viper.Get(i))
}
}
输出:
[initsteps buildsteps runprocess]
initsteps [pip install --upgrade pip python3 --version]
buildsteps [pip install .]
runprocess [python3 test.py]
- 1 回答
- 0 关注
- 118 浏览
添加回答
举报