43 lines
1011 B
Go
43 lines
1011 B
Go
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 {
|
|
config, err := service.toDestinationConfig(nameSpace, sl.toServiceEnv())
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
retConfig += config + "\n\n---\n\n"
|
|
}
|
|
return retConfig, nil
|
|
}
|
|
|
|
func (s Service) toDestinationConfig(nameSpace string, serviceEnv map[string]string) (string, error) {
|
|
var handler Handler
|
|
switch s.Type {
|
|
case go_handler.TypeGolang:
|
|
handler = go_handler.GoServiceHandler{
|
|
NameSpace: nameSpace,
|
|
Name: s.Name,
|
|
Root: s.Root,
|
|
Port: s.Port,
|
|
ServiceEnv: serviceEnv,
|
|
}
|
|
}
|
|
|
|
return handler.ToDestinationConfig()
|
|
}
|