62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
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"`
|
|
AliasName string `json:"alias_name" yaml:"aliasName"`
|
|
Root string `json:"root" yaml:"root"`
|
|
Type string `json:"type" yaml:"type"`
|
|
Port string `json:"port" yaml:"port"`
|
|
Host string `json:"host" yaml:"host"`
|
|
Path string `json:"path" yaml:"path"`
|
|
}
|
|
)
|
|
type (
|
|
ServiceList []Service
|
|
Service struct {
|
|
Name string `json:"name" yaml:"name"`
|
|
AliasName string `json:"alias_name" yaml:"aliasName"`
|
|
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
|
|
}
|