-
-
Notifications
You must be signed in to change notification settings - Fork 211
Open
Description
go.mod
go 1.23.6
require github.com/jinzhu/configor v1.2.2
require (
github.com/BurntSushi/toml v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
config目录是config.go和config.yaml,
config.yaml文件如下:
HttpPort: 8080
DbUrl: test
config.go内容如下:
package config
import (
"encoding/json"
"github.com/jinzhu/configor"
"log"
)
type Config struct {
HttpPort string
DbUrl string
}
var Conf Config
func Init() {
//生产环境需添加 CONFIGOR_ENV=production go run main.go
err := configor.Load(&Conf, "config/config.yaml")
if err != nil {
log.Fatalf("配置加载失败 %v", err)
return
}
js, _ := json.MarshalIndent(&Conf, "", " ")
log.Println("当前环境:", configor.ENV(), "\n", string(js))
}
改为下划线http_port也无法获取到值,运行输出如下
2025/11/19 10:25:20 当前环境: development
{
"HttpPort": "",
"DbUrl": ""
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels