案例分享:基于golang的支付宝支付
时间:2021-07-14 14:33
viper 加载 envfile 配置文件时, 参考如下: 更多golang相关技术文章,请访问golang教程栏目! 以上就是案例分享:基于golang的支付宝支付的详细内容,更多请关注gxlsystem.com其它相关文章!基于 golang 的支付宝支付小案例
使用步骤
git clone git@github.com:yangliang4488/ali_pay_demo.git
cd ali_pay_demo
cp .env.example .env (.env 里请配置相关 appid 、公钥和私钥)go run main.go
避坑
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"