drone_plugin/config_handler/destination_config.go

62 lines
1.3 KiB
Go

package config_handler
import "git.icechen.cn/pkg/drone_plugin/go_handler"
type Handler interface {
ToDestinationConfig() (string, error)
}
func (al ApiList) toDestinationConfig(nameSpace string) (string, error) {
retConfig := ""
for _, api := range al {
config, err := api.toDestinationConfig(nameSpace)
if err != nil {
return "", err
}
retConfig += config + "\n\n---\n\n"
}
return retConfig, nil
}
func (a Api) toDestinationConfig(nameSpace string) (string, error) {
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,
}
}
return handler.ToDestinationConfig()
}
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
retConfig := ""
for _, service := range sl {
config, err := service.toDestinationConfig(nameSpace)
if err != nil {
return "", err
}
retConfig += config + "\n\n---\n\n"
}
return retConfig, nil
}
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
var handler Handler
switch s.Type {
case go_handler.TypeGolang:
handler = go_handler.GoApiHandler{
NameSpace: nameSpace,
Name: s.Name,
Root: s.Root,
Port: s.Port,
}
}
return handler.ToDestinationConfig()
}