太方便了,我以前居然不知道,还得让gpt教我

type Config struct {
    Database struct {
        User          string `yaml:"user"`
    } `yaml:"database"`
}
var GlobalConfig Config

executablePath, _ := os.Executable()
yamlPath := filepath.Join(filepath.Dir(executablePath), "xxxx.yaml")
yamlFile, _ := os.ReadFile(yamlPath)
yaml.Unmarshal(yamlFile, &GlobalConfig)
fmt.Printf("User: %s\n",GlobalConfig.Database.User)

标签: none

添加新评论