drone_plugin/config_handler/api_config.go

36 lines
896 B
Go
Raw Normal View History

2021-12-29 23:23:35 +08:00
package config_handler
2021-12-30 20:06:10 +08:00
import (
"git.icechen.cn/pkg/drone_plugin/consts"
"git.icechen.cn/pkg/drone_plugin/go_handler"
)
2021-12-29 23:23:35 +08:00
2021-12-30 20:06:10 +08:00
func (al ApiList) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
2021-12-29 23:23:35 +08:00
retConfig := ""
for _, api := range al {
2021-12-30 20:06:10 +08:00
config, err := api.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 (a Api) toDestinationConfig(nameSpace string, deployEnv consts.Env, serviceEnv map[string]string) (string, error) {
2021-12-29 23:23:35 +08:00
var handler Handler
switch a.Type {
case go_handler.TypeGolang:
handler = go_handler.GoApiHandler{
NameSpace: nameSpace,
Name: a.Name,
Root: a.Root,
Port: a.Port,
2021-12-30 20:06:10 +08:00
DeployEnv: deployEnv,
2021-12-29 23:23:35 +08:00
ServiceEnv: serviceEnv,
}
}
return handler.ToDestinationConfig()
}