2021-12-28 20:42:51 +08:00
|
|
|
package config_handler
|
|
|
|
|
|
|
|
import "git.icechen.cn/pkg/drone_plugin/go_handler"
|
|
|
|
|
2021-12-29 19:40:57 +08:00
|
|
|
type Handler interface {
|
2021-12-28 20:42:51 +08:00
|
|
|
ToDestinationConfig() (string, error)
|
|
|
|
}
|
|
|
|
|
2021-12-29 20:24:21 +08:00
|
|
|
func (al ApiList) toDestinationConfig(nameSpace string) (string, error) {
|
2021-12-29 19:40:57 +08:00
|
|
|
retConfig := ""
|
|
|
|
for _, api := range al {
|
2021-12-29 20:24:21 +08:00
|
|
|
config, err := api.toDestinationConfig(nameSpace)
|
2021-12-29 19:40:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
retConfig += config + "\n\n---\n\n"
|
|
|
|
}
|
|
|
|
return retConfig, nil
|
2021-12-28 20:42:51 +08:00
|
|
|
}
|
|
|
|
|
2021-12-29 20:24:21 +08:00
|
|
|
func (a Api) toDestinationConfig(nameSpace string) (string, error) {
|
2021-12-29 19:40:57 +08:00
|
|
|
var handler Handler
|
2021-12-28 20:42:51 +08:00
|
|
|
switch a.Type {
|
|
|
|
case go_handler.TypeGolang:
|
2021-12-29 19:40:57 +08:00
|
|
|
handler = go_handler.GoApiHandler{
|
2021-12-29 20:24:21 +08:00
|
|
|
NameSpace: nameSpace,
|
|
|
|
Name: a.Name,
|
|
|
|
Root: a.Root,
|
|
|
|
Port: a.Port,
|
2021-12-29 19:40:57 +08:00
|
|
|
}
|
2021-12-28 20:42:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return handler.ToDestinationConfig()
|
|
|
|
}
|
|
|
|
|
2021-12-29 20:24:21 +08:00
|
|
|
func (sl ServiceList) toDestinationConfig(nameSpace string) (string, error) {
|
2021-12-29 19:40:57 +08:00
|
|
|
retConfig := ""
|
|
|
|
for _, service := range sl {
|
2021-12-29 20:24:21 +08:00
|
|
|
config, err := service.toDestinationConfig(nameSpace)
|
2021-12-29 19:40:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
retConfig += config + "\n\n---\n\n"
|
|
|
|
}
|
|
|
|
return retConfig, nil
|
2021-12-28 20:42:51 +08:00
|
|
|
}
|
|
|
|
|
2021-12-29 20:24:21 +08:00
|
|
|
func (s Service) toDestinationConfig(nameSpace string) (string, error) {
|
2021-12-29 19:40:57 +08:00
|
|
|
var handler Handler
|
|
|
|
switch s.Type {
|
|
|
|
case go_handler.TypeGolang:
|
2021-12-29 21:26:54 +08:00
|
|
|
handler = go_handler.GoServiceHandler{
|
2021-12-29 20:24:21 +08:00
|
|
|
NameSpace: nameSpace,
|
|
|
|
Name: s.Name,
|
|
|
|
Root: s.Root,
|
|
|
|
Port: s.Port,
|
2021-12-29 19:40:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler.ToDestinationConfig()
|
2021-12-28 20:42:51 +08:00
|
|
|
}
|