避坑viper 加载 envfile 配置文件时, 参考如下:
viper.setconfigname(.env)viper.setconfigtype(env) // env 类型viper.addconfigpath(./)if err := viper.readinconfig(); err != nil { fmt.println(err) if _, ok := err.(viper.configfilenotfounderror); ok { fmt.println(.env 配置文件未找到) return }}
官方文档原文: viper.setconfigtype(json) // because there is no file extension in a stream of bytes, supported extensions are json, toml, yaml, yml, properties, props, prop, env, dotenv
更多golang相关技术文章,请访问golang教程栏目!
以上就是案例分享:基于golang的支付宝支付的详细内容。