drone_plugin/config_handler/service_config.go

43 lines
1011 B
Go
Raw Normal View History

2021-12-29 23:23:35 +08:00
package config_handler
import (
"git.icechen.cn/pkg/drone_plugin/go_handler"
"strings"
)
func (sl ServiceList) toServiceEnv() map[string]string {
retMap := make(map[string]string)
for _, service := range sl {
retMap[strings.ToUpper("SERVICE_"+service.Name)] = service.Name + ":" + service.Port
}
return retMap
}
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
retConfig := ""
for _, service := range sl {
2021-12-30 00:00:25 +08:00
config, err := service.toDestinationConfig(nameSpace, sl.toServiceEnv())
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 00:00:25 +08:00
func (s Service) toDestinationConfig(nameSpace string, 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,
Root: s.Root,
Port: s.Port,
ServiceEnv: serviceEnv,
2021-12-29 23:23:35 +08:00
}
}
return handler.ToDestinationConfig()
}