2021-12-29 23:23:35 +08:00
|
|
|
package config_handler
|
|
|
|
|
|
|
|
import (
|
2021-12-30 20:06:10 +08:00
|
|
|
"git.icechen.cn/pkg/drone_plugin/consts"
|
2021-12-29 23:23:35 +08:00
|
|
|
"git.icechen.cn/pkg/drone_plugin/go_handler"
|
|
|
|
)
|
|
|
|
|
2021-12-30 20:06:10 +08:00
|
|
|
func (sl ServiceList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
2021-12-29 23:23:35 +08:00
|
|
|
retConfig := ""
|
|
|
|
for _, service := range sl {
|
2021-12-30 20:06:10 +08:00
|
|
|
config, err := service.toDestinationConfig(nameSpace, deployEnv, serviceEnv)
|
2021-12-29 23:23:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
retConfig += config + "\n\n---\n\n"
|
|
|
|
}
|
|
|
|
return retConfig, nil
|
|
|
|
}
|
|
|
|
|
2021-12-30 20:06:10 +08:00
|
|
|
func (s Service) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
|
2021-12-29 23:23:35 +08:00
|
|
|
var handler Handler
|
|
|
|
switch s.Type {
|
|
|
|
case go_handler.TypeGolang:
|
|
|
|
handler = go_handler.GoServiceHandler{
|
2021-12-30 00:00:25 +08:00
|
|
|
NameSpace: nameSpace,
|
|
|
|
Name: s.Name,
|
2022-01-04 20:56:53 +08:00
|
|
|
AliasName: s.AliasName,
|
2021-12-30 00:00:25 +08:00
|
|
|
Root: s.Root,
|
|
|
|
Port: s.Port,
|
|
|
|
ServiceEnv: serviceEnv,
|
2022-01-04 20:56:53 +08:00
|
|
|
DeployEnv: deployEnv,
|
2021-12-29 23:23:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.ToDestinationConfig()
|
|
|
|
}
|