package yaml

import (
	"gopkg.in/yaml.v2"
	"log"
	"os"
)

type YConfig struct {
	Nacos struct {
		Host        string `yaml:"host"`
		Port        uint64 `yaml:"port"`
		Name        string `yaml:"name"`
		Pass        string `yaml:"pass"`
		Group       string `yaml:"group"`
		DataId      string `yaml:"dataid"`
		ClusterName string `yaml:"clusterName"`
		SentinelId  string `yaml:"sentinelId"`
	}
}

var yconf = YConfig{}

func init() {
	path := os.Getenv("ENV_NACOS_DIR") + "nacos.yaml"

	// 这个需要在containers 配置
	//env:
	//	- name: "release"
	//    value: "galaxy-develop"
	release := os.Getenv("release")

	if release != "" {
		path = "/config/nacos.yaml"
	}

	data, err := os.ReadFile(path)
	if err != nil {
		log.Fatalf("配置文件读取错误:%+v", err)
	} else {
		err = yaml.Unmarshal(data, &yconf)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
}

func GetConf() YConfig {
	return yconf
}
