package config_handler import ( "git.icechen.cn/pkg/drone_plugin/git" "gopkg.in/yaml.v3" "strings" ) const TypeMonorepo = "monorepo" // 单库类型 type Config struct { Kind string `json:"kind" yaml:"kind"` Type string `json:"type" yaml:"type"` Name string `json:"name" yaml:"name"` Api ApiList `json:"api" yaml:"api"` Service ServiceList `json:"service" yaml:"service"` } func (c Config) toServiceEnv() map[string]string { sl := c.Service retMap := make(map[string]string) for _, service := range sl { retMap[strings.ToUpper("SERVICE_"+service.Name)] = c.Name + "-" + service.Name + ":" + service.Port } return retMap } type ( ApiList []Api Api struct { Name string `json:"name" yaml:"name"` Root string `json:"root" yaml:"root"` Type string `json:"type" yaml:"type"` Port string `json:"port" yaml:"port"` } ) type ( ServiceList []Service Service struct { Name string `json:"name" yaml:"name"` Root string `json:"root" yaml:"root"` Type string `json:"type" yaml:"type"` Port string `json:"port" yaml:"port"` } ) // getRealConfig 获取原始配置文件内容 func getRealConfig(client git.Client) (Config, error) { var c Config realConfigContent, err := client.GetRealConfig() if err != nil { return c, err } err = yaml.Unmarshal([]byte(realConfigContent), &c) return c, err }